import jieba import numpy as np import matplotlib.pyplot as plt from plotly.offline.offline import matplotlib from mpl_toolkits.mplot3d import Axes3D from wordcloud import WordCloud, ImageColorGenerator from PIL import Image
boy_name = "MARX·CBR" girl_name = "xxx"
defcount_num(content): marx_count = 0 hr_count = 0 for li in content: if boy_name in li: marx_count += 1 elif girl_name in li: hr_count += 1 print("{} sended : {}".format(boy_name, marx_count)) print("{} sended : {}".format(girl_name, hr_count))
defuse_jieba_and_show(content): words = jieba.lcut(content) # print(words) counts = {} for word in words: iflen(word) == 1: continue else: counts[word] = counts.get(word, 0) + 1
# lab = [] # num = [] for it in items[:20:]: word, count = it print("{}\t{}".format(word, count)) # lab.append(word) # num.append(count) # plt.bar(range(len(lab)), num, tick_label=lab) # plt.show()
for ti in all_msg_time: try: y = int(ti[0:2:]) x = int(ti[3:5:]) z = int(ti[6:8:]) ax.scatter(x, y, z, s=2) except: ... # plt.show() ax.set_zlabel('second') ax.set_ylabel('hour') ax.set_xlabel('minute') plt.savefig('chat_3d.png', dpi=300)
defcloud_img(content): # path_img = "./backgrounds.jpg" # path_img = "./hrs.jpg" # path_img = "./rrby.jfif" all_msg = "" for line in content: if boy_name in line: all_msg += " " elif girl_name in line: all_msg += " " else: msg = remove_pic(line) all_msg += msg generation_cloud_img(all_msg, "cloudword.png")
defseparate_analysis(content): cbr_msg = "" hr_msg = "" flag = 1 for line in content: if boy_name in line: flag = 1 continue elif girl_name in line: flag = 2 continue else: if flag == 1: msg = remove_pic(line) cbr_msg += msg elif flag == 2: msg = remove_pic(line) hr_msg += msg use_jieba_and_show(cbr_msg) use_jieba_and_show(hr_msg) generation_cloud_img(cbr_msg, 'cbr.png') generation_cloud_img(hr_msg, 'hr.png')
if __name__ == '__main__': print('Run it ~') # chat.txt 就是聊天记录 withopen('xxx.txt', 'r', encoding='utf-8') as f: contents = f.readlines()