zoukankan      html  css  js  c++  java
  • 第一个微信小项目

    一、统计自己的好友人数,省市分布等

    def b(f,lis):
        wb=openpyxl.Workbook()
        sheet=wb.active
        sheet.title='list2excel07'
        file_name=f+'.xlsx'
        for i in range(0,len(lis)):
            for j in range(0,len(lis[i])):
                sheet.cell(row=i+1,column=j+1,value=str(lis[i][j]))
        wb.save(file_name)
        print("ok")

    bot=Bot(cache_path=True) friend_all=bot.friends() print(friend_all[0].raw) print(len(friend_all)) lis=[] list_0=['nickname','sex','city','province','signature','headImgUrl','headImgFlag'] lis.append(list_0) for a in friend_all: NickName=a.raw.get('NickName',None) Sex ={1:"",2:"",0:"其它"}.get(a.raw.get('Sex',None),None) City = a.raw.get('City',None) Province = a.raw.get('Province',None) Signature = a.raw.get('Signature',None) HeadImgUrl = a.raw.get('HeadImgUrl',None) HeadImgFlag = a.raw.get('HeadImgFlag',None) list_0=[NickName,Sex,City,Province,Signature,HeadImgUrl,HeadImgFlag] lis.append(list_0)
    b('xlsx',lis) data
    = friend_all.stats_text(total=True, sex=True,top_provinces=30, top_cities=20) print(data)

    结果图为:

    二、用wordcloud库将他们转成图:

    def c(a):
        from wordcloud import WordCloud
        df = read_excel(a,sheetname='list2excel07')
        word_list= df['city'].fillna('0').tolist()
        new_text= ' '.join(word_list)
        wordcloud = WordCloud(font_path='simhei.ttf', background_color="pink").generate(new_text)
        plt.imshow(wordcloud)
        plt.axis("off")
        plt.show()

    结果图为:

    三、用pyecharts的则为:

    四、在中国的分布图为:

    def e(a):
        from pyecharts import Map
        df = read_excel(a,sheetname='list2excel07')
        province_list = df['province'].fillna('NAN').tolist()
        count_province = pd.value_counts(province_list)
        value =count_province.tolist() 
        attr =count_province.index.tolist()
        map=Map("各省微信好友分布", width=1200, height=600) 
        map.add("", attr, value, maptype='china', is_visualmap=True, visual_text_color='#000',is_label_show = True)
        map.show_config() 
        map.render(r'map1.html')

    结果图:

     五、用Python制作一个微信机器人:

    def talk(info='你好啊'):
        api_url = 'http://www.tuling123.com/openapi/api' 
        apikey='de48a0c4ce1f4851b5a2a9fc1ce852fa'
        data ={'key': apikey, 'info': info}
        r = requests.post(api_url, data=data).text
        response = json.loads(r)['text']
        print(response)

    结果有:你好,愿你每天都有好心情。

    六、做一个自动回复好友的机器人:

    import itchat
    import requests
    def get_response(msg):
        apiurl = 'http://i.itpk.cn/api.php'
        data={
            "question": msg,
            "api_key": "填入自己的apikey",
            "api_secret": "填自己的apisecret"                  #如果关闭可以不用这一句
        }
    
        r=requests.post(apiurl,data=data)
        return r.text
    @itchat.msg_register(itchat.content.TEXT)
    def print_content(msg):
        return get_response(msg['Text'])
    itchat.auto_login(True)
    itchat.run()

    如果要自动回复群的,可以加入:

    @itchat.msg_register([itchat.content.TEXT], isGroupChat=True)
    def print_content(msg):
        return get_response(msg['Text'])

     提醒:如果有小号,尽量用小号做这个机器人的实验

  • 相关阅读:
    C# Redis实战(五)
    C# Redis实战(四)
    C# Redis实战(三)
    C# Redis实战(二)
    C# Redis实战(一)
    memcached的基本命令(安装、卸载、启动、配置相关)
    git和tortoisegit安装教程
    编程规范是非常重要的,为什么说可读性比什么都重要?你有没有确定一个编程规范呢?
    关于VR游戏的前景
    在项目开发过程中如何处理人际关系
  • 原文地址:https://www.cnblogs.com/13128870440-zxy/p/10965347.html
Copyright © 2011-2022 走看看