itchat

# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import itchat, time
def lc():
    print("Finash Login!")
def ec():
    print("exit")

itchat.auto_login(loginCallback=lc, exitCallback=ec,hotReload=True)
friends=itchat.get_friends()
#print flist
male = female = other = 0
city={}
for i in friends[1:]:
    
    c= i["City"]
    if city.has_key(c) :
        city[c]=city[c]+1
    else:
        city[c]=1
        
    sex = i["Sex"]
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other +=1
#计算朋友总数
total = len(friends[1:])

#打印出自己的好友性别比例
print("男性好友: %.2f%%" % (float(male)/total*100) + "\n" +
"女性好友: %.2f%%" % (float(female) / total * 100) + "\n" +
"不明性别好友: %.2f%%" % (float(other) / total * 100))

for (k,v) in city.items():
    print k,v

  

posted @ 2019-01-02 15:43  ahuo  阅读(178)  评论(0编辑  收藏  举报