#coding=utf-8
import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
import itchat
# itchat.login()
# itchat.send(u"您好",'filehelper')
#这样你就可以保持一段时间登录状态,而不用每次运行代码都要扫码登录了!
itchat.auto_login(hotReload=True)
itchat.dump_login_status()
itchat.send(u"您好",'filehelper') #给自己的文件传输助手发送消息
friends=itchat.get_friends(update=True)[:]
total=len(friends)-1
male=female=other=0
for friend in friends[1:]:
sex=friend["Sex"]
if sex==1:
male+=1
elif sex==2:
female+=1
else:
other+=1
from echarts import Echart,Legend,Pie
chart=Echart("%s的微信好友性别比例" %(friends[0])['NickName'],'from Wechat')
chart.use(Pie('WeChat',
[{'value': male, 'name': '男性 %.2f%%' % (float(male) / total * 100)},
{'value': female, 'name': '女性 %.2f%%' % (float(female) / total * 100)},
{'value': other, 'name': '其他 %.2f%%' % (float(other) / total * 100)}],
radius=["50%", "70%"]))
chart.use(Legend(["male", "female", "other"]))
del chart.json["xAxis"]
del chart.json["yAxis"]
chart.plot()
--------
运行后会自动弹出微信登录二维码,扫码后登陆微信成功