Use iTunes and iTools to extract Wechat chat history
# -*- coding:utf-8 -*- | |
import os | |
import re | |
import jieba.analyse | |
import matplotlib.pyplot as plt | |
from wordcloud import WordCloud | |
__author__ = 'wittyfilter' | |
data = [] | |
jieba.analyse.set_stop_words("stopwords.txt") | |
pattern = re.compile(r'\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}|接收|发送|未知类型|网页消息|系统通知|文字|表情|图片|视频|我|[??]|、|[!!]|。') | |
# Replace xxx with your chat history file | |
with open("xxx.txt") as f: | |
mytext = f.readlines() | |
for line in mytext: | |
line = re.sub(pattern, '', line) | |
data.extend(jieba.analyse.extract_tags(line, topK=20)) | |
data = " ".join(data) | |
wordcloud = WordCloud(width=640, | |
height=480, | |
collocations=False, | |
font_path='Songti', | |
background_color='white', | |
).generate(data) | |
# Replace xxx with your own name | |
plt.title('xxx') | |
plt.imshow(wordcloud, interpolation="bilinear") | |
plt.axis('off') | |
plt.savefig('xxx.jpg', dpi=1600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment