Python写一个微信个性签名词云

#!/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()

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值