Merge pull request #128 from XingHehy/master

词云分开统计
This commit is contained in:
SiYuan 2023-12-13 20:02:37 +08:00 committed by GitHub
commit 48830a648c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 17 deletions

View File

@ -17,7 +17,7 @@ wordcloud_width = 780
wordcloud_height = 720
def wordcloud(wxid, is_Annual_report=False, year='2023'):
def wordcloud(wxid, is_Annual_report=False, year='2023', who='1'):
import jieba
txt_messages = msg_db.get_messages_by_type(wxid, MsgType.TEXT, is_Annual_report, year)
if not txt_messages:
@ -27,7 +27,9 @@ def wordcloud(wxid, is_Annual_report=False, year='2023'):
'max_num': "0",
'dialogs': []
}
text = ''.join(map(lambda x: x[7], txt_messages))
# text = ''.join(map(lambda x: x[7], txt_messages))
text = ''.join(map(lambda x: x[7] if x[4] == int(who) else '', txt_messages)) # 1“我”说的话0“Ta”说的话
total_msg_len = len(text)
# 使用jieba进行分词并加入停用词
words = jieba.cut(text)

View File

@ -63,22 +63,22 @@
<iframe src="/home" frameborder="0" height="100%" width="100%" class="if00"></iframe>
</div>
<div id="page2" class="page">
<iframe src="/wordcloud" frameborder="0" height="100%" width="100%" class="if00"></iframe>
<iframe src="/wordcloud/1" frameborder="0" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #8a6d3b" id="page3" class="page">
<div id="page3" class="page">
<iframe src="/wordcloud/0" frameborder="0" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #8a6d3b" id="page4" class="page">
<iframe src="/test" frameborder="0" id="iframe0" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #337ab7" id="page4" class="page">
<div style="background-color: #337ab7" id="page5" class="page">
<iframe src="test" frameborder="0" id="iframe3" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #337ab7" id="page5" class="page">
<div style="background-color: #337ab7" id="page6" class="page">
<iframe src="test" frameborder="0" id="iframe4" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #337ab7" id="page6" class="page">
<iframe src="test" frameborder="0" id="iframe5" height="100%" width="100%" class="if00"></iframe>
</div>
<div style="background-color: #337ab7" id="page7" class="page">
<iframe src="test" frameborder="0" id="iframe6" height="100%" width="100%" class="if00"></iframe>
<iframe src="test" frameborder="0" id="iframe5" height="100%" width="100%" class="if00"></iframe>
</div>
</div>
</div>

View File

@ -32,7 +32,7 @@
<div class="bg f-page"></div>
<div class="tt f-animOpac" style="font-size:30px !important">
<h1>二零二三</h1>
<h1>说的最多的是</h1></div>
<h1>{{ who }}说的最多的是</h1></div>
<div class="ckeywords j-anim01 z-anim">
<div class="hands">
<div class="hand2"></div>
@ -96,4 +96,4 @@
</body>
</html>
</html>

View File

@ -34,15 +34,17 @@ def home():
return render_template('home.html', **data)
@app.route('/wordcloud')
def one():
@app.route('/wordcloud/<who>/')
def one(who):
wxid = contact.wxid
# wxid = 'wxid_lltzaezg38so22'
world_cloud_data = analysis.wordcloud(wxid)
# print('wxid:'+wxid)
world_cloud_data = analysis.wordcloud(wxid,who=who) # 获取与Ta的对话数据
# print(world_cloud_data)
who = "" if who == '1' else "TA"
with open('wordcloud.html', 'w', encoding='utf-8') as f:
f.write(render_template('wordcloud.html', **world_cloud_data))
return render_template('wordcloud.html', **world_cloud_data)
return render_template('wordcloud.html', **world_cloud_data,who=who)
def set_text(text):