使用itchat,将微信好友的名字拼接成词云

2018-06-13  本文已影响0人  ifqu
from PIL import Image,ImageSequence
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud,ImageColorGenerator
import itchat
import jieba
itchat.auto_login(hotReload=True)
frinds=itchat.get_friends(update=True)[0:]
keywords=''
for i in frinds:
    keywords=keywords+','+i['RemarkName']#修改键值可以获取不同的拼接内容
print(keywords)
number=len(keywords)
image= Image.open('timg.jpg')#作为词云背景的图片
graph = np.array(image)
wc = WordCloud(background_color='White',max_words=number,mask=graph,margin=2,font_path='/Users/fuqi/Desktop/biyesheji/zhiti/DroidSansFallbackFull.ttf').generate(keywords)#需要加入中文的字体
image_color = ImageColorGenerator(graph)
plt.figure()
plt.imshow(wc)
plt.axis('off')
plt.show()
wc.to_file('wei.jpg')
itchat.send_image('wei.jpg','filehelper')#将词云发送给文件传输助手
上一篇下一篇

猜你喜欢

热点阅读