博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第一个微信小项目
阅读量:6965 次
发布时间:2019-06-27

本文共 2870 字,大约阅读时间需要 9 分钟。

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

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 itchatimport requestsdef 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'])

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

转载于:https://www.cnblogs.com/13128870440-zxy/p/10965347.html

你可能感兴趣的文章
Vue2.0 探索之路——生命周期和钩子函数的一些理解
查看>>
实验一 网络侦查与网络扫描
查看>>
数据结构学习笔记(3)_使用数组实现简单线性表功能
查看>>
微信小程序底部tabbar
查看>>
linux kernel map
查看>>
python利用opencv合成模糊图像
查看>>
dataframe splict
查看>>
hadoop环境搭建(linux单机版)
查看>>
nodejs 像 C 语言那样输出当前代码的行数
查看>>
luogo p3379 【模板】最近公共祖先(LCA)
查看>>
[考试]20150925
查看>>
12、K最近邻算法(KNN算法)
查看>>
如何使用crash分析vmcore - 之基础思路case1
查看>>
我所认知的电子商务解决方案
查看>>
关于float、double结果精度的问题
查看>>
css基础之 联网使用bootstrap
查看>>
bzoj2743 [HEOI2012]采花
查看>>
C语言综合实验1—学生信息管理系统
查看>>
总体框架
查看>>
hdu4417
查看>>