Python之获取微信好友信息

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))

 

posted @ 2018-08-29 14:49  Shiyu_Huang  阅读(463)  评论(0编辑  收藏  举报