#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File : wxfriends_information.py
# Author: PengLei
# Date : 2018/8/2
import itchat ,time,sys,xlwt
from pyecharts import WordCloud
import random
file = xlwt.Workbook()
table = file.add_sheet('info', cell_overwrite_ok=True)
itchat.auto_login(hotReload=True)
print(u'logged')
friends = itchat.get_friends(update=True)[0:]
male = female = other = 0
for i in friends[1:]:
sex = i["Sex"]
if sex == 1:
male += 1
elif sex == 2:
female += 1
else:
other += 1
total = len(friends[1:])
table.write(0, 5, u'[made by Dwyane]')
table.write(0, 7, u'[共'+str(len(friends)-1)+u'位朋友,'+str(male)+u'位男性朋友,'+str(female)+u'位女性朋友,另外'+str(other)+u'位不明性别]')
table.write(0, 0, u'[昵称]')
table.write(0,1,u'[备注名]')
table.write(0,2,u'[省份]')
table.write(0,3,u'[城市]')
table.write(0,4,u'[签名]')
a=0
sign = []
for i in friends:
table.write(a+1,0,i['NickName'])
table.write(a+1,1,i['RemarkName'])
table.write(a+1,2,i['Province'])
table.write(a+1,3,i['City'])
table.write(a+1,4,i['Signature'])
sign.append(i['Signature'])
if i['RemarkName'] == u'':
table.write(a+1,1,u'[ ]')
if i['Province'] == u'':
table.write(a+1,2,u'[ ]')
if i['City'] == u'':
table.write(a+1,3,u'[ ]')
if i['Signature'] == u'':
table.write(a+1,4,u'[ ]')
a=a+1
print(a)
print(sign)
print(type(sign))
# qm=raw_input("file name >>>:")
aaa='weixin_'+time.strftime("%Y%m%d", time.localtime())+'.xls'
file.save(aaa)
itchat.send('made by Dwyane','filehelper')
itchat.send('@%s@%s' % ('fil',aaa), 'filehelper')
print ("over")
# name = [
# 'Sam S Club', 'Macys', 'Amy Schumer', 'Jurassic World', 'Charter Communications',
# 'Chick Fil A', 'Planet Fitness', 'Pitch Perfect', 'Express', 'Home', 'Johnny Depp',
# 'Lena Dunham', 'Lewis Hamilton', 'KXAN', 'Mary Ellen Mark', 'Farrah Abraham',
# 'Rita Ora', 'Serena Williams', 'NCAA baseball tournament', 'Point Break']
attr = sign
print(len(attr))
# value = [np.random.randint(0, 1000, size = len(sign))]
value = []
for i in range(0, len(attr)):
value.append(random.randint(0,1000))
print('value', len(value))
wordcloud = WordCloud(width=1366, height=768)
wordcloud.add("", attr, value, word_size_range=[12, 40])
wordcloud.render()