diff --git a/app/DataBase/media_msg.py b/app/DataBase/media_msg.py index b188f8e..8e07183 100644 --- a/app/DataBase/media_msg.py +++ b/app/DataBase/media_msg.py @@ -55,17 +55,20 @@ class MediaMsg: silk_path = f"{output_path}\\{reserved0}.silk" pcm_path = f"{output_path}\\{reserved0}.pcm" mp3_path = f"{output_path}\\{reserved0}.mp3" - slik_path = silk_path.replace("/", "\\") + silk_path = silk_path.replace("/", "\\") pcm_path = pcm_path.replace("/", "\\") mp3_path = mp3_path.replace("/", "\\") - print(mp3_path) if os.path.exists(mp3_path): return mp3_path - open(silk_path, "wb").write(buf) + with open(silk_path, "wb") as f: + f.write(buf) + # open(silk_path, "wb").write() decode(silk_path, pcm_path, 44100) - system(f'ffmpeg.exe -loglevel quiet -y -f s16le -i "{pcm_path}" -ar 44100 -ac 1 "{mp3_path}"') - system(f'del "{silk_path}"') - system(f'del "{pcm_path}"') + cmd = f'''{os.path.join(os.getcwd(),'app','resources','ffmpeg.exe')} -loglevel quiet -y -f s16le -i {pcm_path} -ar 44100 -ac 1 {mp3_path}''' + system(cmd) + system(f'del {silk_path}') + system(f'del {pcm_path}') + print(mp3_path) return mp3_path def get_audio_text(self, content): diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index a3edea3..0f4dea4 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -203,10 +203,16 @@ class Msg: for dialog in temp: msg1 = dialog[0] msg2 = dialog[1] - res.append(( - (msg1[4], msg1[5], msg1[7].split(keyword), msg1[8]), - (msg2[4], msg2[5], msg2[7], msg2[8]) - )) + try: + res.append(( + (msg1[4], msg1[5], msg1[7].split(keyword), msg1[8]), + (msg2[4], msg2[5], msg2[7], msg2[8]) + )) + except TypeError: + res.append(( + ('', '', ['', ''], ''), + ('', '', '', '') + )) return res def get_messages_by_days(self, username_, is_Annual_report_=False, year_='2023'): diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index 24de94f..a509740 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -319,9 +319,20 @@ class ChildThread(QThread): ) elif self.output_type==Output.TXT: name = '你' if is_send else self.contact.remark - doc.write( - f'''{str_time} {name}\n{content.get('title')}\n引用:{refer_msg.get('displayname')}:{refer_msg.get('content')}\n\n''' - ) + if refer_msg: + referText = f"{refer_msg.get('displayname')}:{refer_msg.get('content')}" + emojiText = findall(r"(\[.+?\])", referText) + for emoji_text in emojiText: + if emoji_text in emoji: + referText = referText.replace(emoji_text, emoji[emoji_text]) + doc.write( + f'''{str_time} {name}\n{content.get('title')}\n引用:{refer_msg.get('displayname')}:{refer_msg.get('content')}\n\n''' + ) + else: + doc.write( + f'''{str_time} {name}\n{content.get('title')}\n引用:未知\n\n''' + ) + def system_msg(self, doc, message): str_content = message[7] diff --git a/app/analysis/analysis.py b/app/analysis/analysis.py index 430179d..5eb13fe 100644 --- a/app/analysis/analysis.py +++ b/app/analysis/analysis.py @@ -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) diff --git a/app/resources/ffmpeg.exe b/app/resources/ffmpeg.exe new file mode 100644 index 0000000..e576a7c Binary files /dev/null and b/app/resources/ffmpeg.exe differ diff --git a/app/web_ui/templates/index.html b/app/web_ui/templates/index.html index 6fcb123..4507f9d 100644 --- a/app/web_ui/templates/index.html +++ b/app/web_ui/templates/index.html @@ -63,22 +63,22 @@
- +
-
+
+ +
+
-
+
-
+
-
- -
- +
diff --git a/app/web_ui/templates/wordcloud.html b/app/web_ui/templates/wordcloud.html index 42ee078..79f9f45 100644 --- a/app/web_ui/templates/wordcloud.html +++ b/app/web_ui/templates/wordcloud.html @@ -32,7 +32,7 @@

二零二三

-

你说的最多的是

+

{{ who }}说的最多的是

@@ -96,4 +96,4 @@ - \ No newline at end of file + diff --git a/app/web_ui/web.py b/app/web_ui/web.py index 37e7d49..77e8b7d 100644 --- a/app/web_ui/web.py +++ b/app/web_ui/web.py @@ -34,15 +34,17 @@ def home(): return render_template('home.html', **data) -@app.route('/wordcloud') -def one(): +@app.route('/wordcloud//') +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): diff --git a/requirements_pc.txt b/requirements_pc.txt index 18c0be7..713b142 100644 --- a/requirements_pc.txt +++ b/requirements_pc.txt @@ -16,4 +16,4 @@ google==3.0.0 protobuf==4.25.1 soupsieve==2.5 lz4==4.3.2 -pilk \ No newline at end of file +pilk==0.2.4 \ No newline at end of file