700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 使用wxpy统计微信好友数量及男女数量 并保存好友数据到本地

使用wxpy统计微信好友数量及男女数量 并保存好友数据到本地

时间:2020-06-05 09:54:38

相关推荐

使用wxpy统计微信好友数量及男女数量 并保存好友数据到本地

使用wxpy统计微信好友数量及男女数量,并保存好友数据到本地,代码如下:

from wxpy import *import jsonclass bots:def __init__(self):passdef initBot(self):bot = Bot()my_friend = bot.friends();self.friendsArr=[]sexArr=['未知','男','女']for ff in my_friend:ffDict={}ffDict.update({'wxid':ff.wxid})ffDict.update({'city':ff.city})ffDict.update({'sex':sexArr[ff.sex]})ffDict.update({'isFriend':ff.is_friend.nick_name})ffDict.update({'nick_name':ff.nick_name})ffDict.update({'user_name':ff.user_name})ffDict.update({'province':ff.province})ffDict.update({'remark_name':ff.remark_name})self.friendsArr.append(ffDict)def setFriendsDataToJson(self,fileName):f=open(fileName,'w+')jstr=json.dumps(self.friendsArr)f.write(jstr)def getTheSexNum(self):unknown,male,female=0,0,0# print(self.friendsArr[0])# returnfor item in self.friendsArr:if item.get('sex')=='男':male+=1elif item.get('sex')=="女":female+=1else:unknown+=1print('count:'+str(len(self.friendsArr)),'男:'+str(male),'女:'+str(female))botObj=bots()botObj.initBot()botObj.getTheSexNum()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。