diff --git a/app/log/exception_handling.py b/app/log/exception_handling.py index ea71536..7381eb8 100644 --- a/app/log/exception_handling.py +++ b/app/log/exception_handling.py @@ -40,10 +40,3 @@ def excepthook(exc_type, exc_value, traceback_): # 调用原始的 excepthook,以便程序正常退出 sys.__excepthook__(exc_type, exc_value, traceback_) - - -# 设置 excepthook -sys.excepthook = excepthook -result = None # 假设这里返回了一个 None -for item in result: # 尝试迭代一个 None - print(item) \ No newline at end of file diff --git a/app/ui/contact/contactInfo.py b/app/ui/contact/contactInfo.py index 15b06d9..75d00b8 100644 --- a/app/ui/contact/contactInfo.py +++ b/app/ui/contact/contactInfo.py @@ -71,7 +71,7 @@ class ContactInfo(QWidget, Ui_Form): self.report_thread = ReportThread(self.contact) # self.report_thread.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314"))) self.report_thread.start() - QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/charts")) + QDesktopServices.openUrl(QUrl(f"http://127.0.0.1:21314/charts/{self.contact.wxid}")) def annual_report(self): date_range = None @@ -95,9 +95,8 @@ class ContactInfo(QWidget, Ui_Form): self.contact.save_avatar() Me().save_avatar() self.report_thread = ReportThread(self.contact, time_range) - self.report_thread.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314"))) self.report_thread.start() - QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/christmas")) + QDesktopServices.openUrl(QUrl(f"http://127.0.0.1:21314/christmas/{self.contact.wxid}")) def emotionale_Analysis(self): QDesktopServices.openUrl(QUrl("https://memotrace.lc044.love/")) diff --git a/app/web_ui/templates/charts.html b/app/web_ui/templates/charts.html index 0339fc1..dc2a2cf 100644 --- a/app/web_ui/templates/charts.html +++ b/app/web_ui/templates/charts.html @@ -58,7 +58,19 @@ setInterval(getRTime, 1000); - - - diff --git a/app/web_ui/templates/christmas.html b/app/web_ui/templates/christmas.html index 120b1a0..5361bb1 100644 --- a/app/web_ui/templates/christmas.html +++ b/app/web_ui/templates/christmas.html @@ -8,9 +8,9 @@ - - - + + +
diff --git a/app/web_ui/web.py b/app/web_ui/web.py index 125f757..b2ff1cf 100644 --- a/app/web_ui/web.py +++ b/app/web_ui/web.py @@ -3,16 +3,17 @@ import sys import time import requests -from flask import Flask, render_template, send_file, jsonify, make_response +from flask import Flask, render_template, send_file, jsonify, make_response, request from pyecharts.charts import Bar -from app.DataBase import msg_db +from app.DataBase import msg_db, micro_msg_db from app.analysis import analysis from app.person import Contact, Me from app.util.emoji import get_most_emoji app = Flask(__name__) +run_flag = False wxid = '' contact: Contact = None start_time = '2023-1-01 00:00:00' @@ -21,6 +22,19 @@ time_range = (start_time, end_time) html: str = '' api_url = 'http://api.lc044.love/upload' +def get_contact(wxid): + contact_info_list = micro_msg_db.get_contact_by_username(wxid) + contact_info = { + 'UserName': contact_info_list[0], + 'Alias': contact_info_list[1], + 'Type': contact_info_list[2], + 'Remark': contact_info_list[3], + 'NickName': contact_info_list[4], + 'smallHeadImgUrl': contact_info_list[7], + 'label_name': contact_info_list[10], + } + contact = Contact(contact_info) + return contact @app.route("/") def index(): @@ -28,9 +42,9 @@ def index(): return "index.html" -@app.route("/christmas") -def christmas(): - +@app.route("/christmas/") +def christmas(wxid): + contact = get_contact(wxid) # 渲染模板,并传递图表的 HTML 到模板中 try: first_message, first_time = msg_db.get_first_time_of_message(contact.wxid) @@ -160,9 +174,14 @@ def test(): def run(port=21314): - try: - app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False) - except: + global run_flag + if not run_flag: + try: + app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False) + run_flag = True + except: + pass + else: pass @@ -181,30 +200,32 @@ def get_image(filename): return send_file(os.path.join(f"{os.getcwd()}/data/avatar/", filename), mimetype='image/png') -@app.route('/month_count') +@app.route('/month_count', methods=['POST']) def get_chart_options(): time_range = (0, time.time()) data = analysis.month_count(contact.wxid, time_range=time_range) return jsonify(data) -@app.route('/wordcloud') +@app.route('/wordcloud', methods=['POST']) def get_wordcloud(): - time_range = (0, time.time()) - print(time_range, contact.wxid) + wxid = request.json.get('wxid') + time_range = request.json.get('time_range', []) - world_cloud_data = analysis.wordcloud_(contact.wxid, time_range=time_range) + world_cloud_data = analysis.wordcloud_(wxid, time_range=time_range) return jsonify(world_cloud_data) -@app.route('/charts') -def charts(): +@app.route('/charts/') +def charts(wxid): # 渲染模板,并传递图表的 HTML 到模板中 + contact = get_contact(wxid) try: - first_message, first_time = msg_db.get_first_time_of_message(contact.wxid) + first_message, first_time = msg_db.get_first_time_of_message(wxid) except TypeError: first_time = '2023-01-01 00:00:00' data = { + 'wxid':wxid, 'my_nickname': Me().name, 'ta_nickname': contact.remark, 'first_time': first_time @@ -212,16 +233,19 @@ def charts(): return render_template('charts.html', **data) -@app.route('/calendar') +@app.route('/calendar', methods=['POST']) def get_calendar(): - time_range = (0, time.time()) - world_cloud_data = analysis.calendar_chart(contact.wxid, time_range=time_range) + wxid = request.json.get('wxid') + time_range = request.json.get('time_range',[]) + world_cloud_data = analysis.calendar_chart(wxid, time_range=time_range) return jsonify(world_cloud_data) -@app.route('/message_counter') +@app.route('/message_counter', methods=['POST']) def get_counter(): - time_range = (0, time.time()) + wxid = request.json.get('wxid') + time_range = request.json.get('time_range', []) + contact = get_contact(wxid) data = analysis.sender(contact.wxid, time_range=time_range, my_name=Me().name, ta_name=contact.remark) return jsonify(data)