您的位置:首页 > 编程语言 > Python开发

Python之获取微信好友信息

2018-08-29 14:49 651 查看

save_info.py:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import itchat
import pickle
itchat.auto_login(hotReload=True)
itchat.dump_login_status()

friends = itchat.get_friends(update=True)[:]

def save_obj(obj, name ):
with open(name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)

save_obj(friends,'friends')

 

show_info.py

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pickle
def load_obj(name ):
with open( name + '.pkl', 'rb') as f:
return pickle.load(f)

friends = load_obj('friends')
total = len(friends) - 1
man = women = other = 0

for friend in friends[0:] :
sex = friend["Sex"]

if sex == 1 :
man += 1
elif sex == 2 :
women += 1
else :
other += 1

print u'姓名:{} 昵称:{} 格言{}'.format(friend["RemarkName"],friend["NickName"],friend["Signature"])

ss =  '🐯🍉🍀🙆🏼💧🐬🌈🐑🐠🙈🐰🍋🤪🌟🌧🍇🔔🎉💎💍👑'
for i in range(int(len(ss)/4)):
print ss[i*4:(i+1)*4]

print("男性好友:%d" % (man))
print("女性好友:%d" % (women))

print("男性好友:%.2f%%" % (float(man) / total * 100))
print("女性好友:%.2f%%" % (float(women) / total * 100))
print("其他:%.2f%%" % (float(other) / total * 100))

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: