修改年度报告url

This commit is contained in:
SiYuan 2024-02-08 22:54:57 +08:00
parent e817b868ba
commit cb83c5bd81
5 changed files with 108 additions and 44 deletions

View File

@ -40,10 +40,3 @@ def excepthook(exc_type, exc_value, traceback_):
# 调用原始的 excepthook以便程序正常退出 # 调用原始的 excepthook以便程序正常退出
sys.__excepthook__(exc_type, exc_value, traceback_) sys.__excepthook__(exc_type, exc_value, traceback_)
# 设置 excepthook
sys.excepthook = excepthook
result = None # 假设这里返回了一个 None
for item in result: # 尝试迭代一个 None
print(item)

View File

@ -71,7 +71,7 @@ class ContactInfo(QWidget, Ui_Form):
self.report_thread = ReportThread(self.contact) 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.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314")))
self.report_thread.start() 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): def annual_report(self):
date_range = None date_range = None
@ -95,9 +95,8 @@ class ContactInfo(QWidget, Ui_Form):
self.contact.save_avatar() self.contact.save_avatar()
Me().save_avatar() Me().save_avatar()
self.report_thread = ReportThread(self.contact, time_range) 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() 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): def emotionale_Analysis(self):
QDesktopServices.openUrl(QUrl("https://memotrace.lc044.love/")) QDesktopServices.openUrl(QUrl("https://memotrace.lc044.love/"))

View File

@ -58,7 +58,19 @@ setInterval(getRTime, 1000);
</script> </script>
<script> <script>
fetch('/month_count') var wxid = '{{wxid}}';
function month_count(time_range){
const requestData = {
wxid: wxid,
time_range: time_range
};
fetch('/month_count',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
})
.then(response => response.json()) .then(response => response.json())
.then(chartOptions => { .then(chartOptions => {
// 在这里使用 ECharts 渲染图表 // 在这里使用 ECharts 渲染图表
@ -66,9 +78,19 @@ setInterval(getRTime, 1000);
var option = chartOptions.chart_data; var option = chartOptions.chart_data;
myChart.setOption(JSON.parse(option)); myChart.setOption(JSON.parse(option));
}); });
</script> }
<script> function wordcloud(time_range){
fetch('/wordcloud') const requestData = {
wxid: wxid,
time_range: time_range
};
fetch('/wordcloud',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
})
.then(response => response.json()) .then(response => response.json())
.then(chartOptions => { .then(chartOptions => {
// 在这里使用 ECharts 渲染图表 // 在这里使用 ECharts 渲染图表
@ -76,9 +98,19 @@ setInterval(getRTime, 1000);
var option = chartOptions.chart_data; var option = chartOptions.chart_data;
myChart.setOption(JSON.parse(option)); myChart.setOption(JSON.parse(option));
}); });
</script> }
<script> function calendar(time_range){
fetch('/calendar') const requestData = {
wxid: wxid,
time_range: time_range
};
fetch('/calendar',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
})
.then(response => response.json()) .then(response => response.json())
.then(chartOptions => { .then(chartOptions => {
// 在这里使用 ECharts 渲染图表 // 在这里使用 ECharts 渲染图表
@ -86,9 +118,19 @@ setInterval(getRTime, 1000);
var option = chartOptions.chart_data; var option = chartOptions.chart_data;
myChart.setOption(JSON.parse(option)); myChart.setOption(JSON.parse(option));
}); });
</script> }
<script> function message_counter(time_range){
fetch('/message_counter') const requestData = {
wxid: wxid,
time_range: time_range
};
fetch('/message_counter',{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
})
.then(response => response.json()) .then(response => response.json())
.then(chartOptions => { .then(chartOptions => {
// 在这里使用 ECharts 渲染图表 // 在这里使用 ECharts 渲染图表
@ -102,6 +144,12 @@ setInterval(getRTime, 1000);
var option = chartOptions.chart_data_weekday; var option = chartOptions.chart_data_weekday;
myChart2.setOption(JSON.parse(option)); myChart2.setOption(JSON.parse(option));
}); });
}
var time_range=['1997-01-01 00:00:00','2035-01-01 00:00:00']
message_counter(time_range);
month_count(time_range);
calendar(time_range);
wordcloud(time_range);
</script> </script>
</body> </body>
</html> </html>

View File

@ -8,9 +8,9 @@
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@latest/dist/echarts.min.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@latest/dist/echarts.min.js"></script>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts-wordcloud.min.js"></script> <script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts-wordcloud.min.js"></script>
<link rel="stylesheet" href="https://memotrace.lc044.love/static/css/fullpage.min.css" /> <link rel="stylesheet" href="https://memotrace.lc044.love/static/css/fullpage.min.css" />
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <script type="text/javascript" src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script src="https://memotrace.lc044.love/static/js/fullpage.min.js"></script> <script type="text/javascript" src="https://memotrace.lc044.love/static/js/fullpage.min.js"></script>
<script src="https://davidshimjs.github.io/qrcodejs/qrcode.min.js"></script> <script type="text/javascript" src="https://davidshimjs.github.io/qrcodejs/qrcode.min.js"></script>
</head> </head>
<body> <body>
<div id="snow"></div> <div id="snow"></div>

View File

@ -3,16 +3,17 @@ import sys
import time import time
import requests 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 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.analysis import analysis
from app.person import Contact, Me from app.person import Contact, Me
from app.util.emoji import get_most_emoji from app.util.emoji import get_most_emoji
app = Flask(__name__) app = Flask(__name__)
run_flag = False
wxid = '' wxid = ''
contact: Contact = None contact: Contact = None
start_time = '2023-1-01 00:00:00' start_time = '2023-1-01 00:00:00'
@ -21,6 +22,19 @@ time_range = (start_time, end_time)
html: str = '' html: str = ''
api_url = 'http://api.lc044.love/upload' 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("/") @app.route("/")
def index(): def index():
@ -28,9 +42,9 @@ def index():
return "index.html" return "index.html"
@app.route("/christmas") @app.route("/christmas/<wxid>")
def christmas(): def christmas(wxid):
contact = get_contact(wxid)
# 渲染模板,并传递图表的 HTML 到模板中 # 渲染模板,并传递图表的 HTML 到模板中
try: 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(contact.wxid)
@ -160,9 +174,14 @@ def test():
def run(port=21314): def run(port=21314):
try: global run_flag
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False) if not run_flag:
except: try:
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)
run_flag = True
except:
pass
else:
pass pass
@ -181,30 +200,32 @@ def get_image(filename):
return send_file(os.path.join(f"{os.getcwd()}/data/avatar/", filename), mimetype='image/png') 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(): def get_chart_options():
time_range = (0, time.time()) time_range = (0, time.time())
data = analysis.month_count(contact.wxid, time_range=time_range) data = analysis.month_count(contact.wxid, time_range=time_range)
return jsonify(data) return jsonify(data)
@app.route('/wordcloud') @app.route('/wordcloud', methods=['POST'])
def get_wordcloud(): def get_wordcloud():
time_range = (0, time.time()) wxid = request.json.get('wxid')
print(time_range, contact.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) return jsonify(world_cloud_data)
@app.route('/charts') @app.route('/charts/<wxid>')
def charts(): def charts(wxid):
# 渲染模板,并传递图表的 HTML 到模板中 # 渲染模板,并传递图表的 HTML 到模板中
contact = get_contact(wxid)
try: 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: except TypeError:
first_time = '2023-01-01 00:00:00' first_time = '2023-01-01 00:00:00'
data = { data = {
'wxid':wxid,
'my_nickname': Me().name, 'my_nickname': Me().name,
'ta_nickname': contact.remark, 'ta_nickname': contact.remark,
'first_time': first_time 'first_time': first_time
@ -212,16 +233,19 @@ def charts():
return render_template('charts.html', **data) return render_template('charts.html', **data)
@app.route('/calendar') @app.route('/calendar', methods=['POST'])
def get_calendar(): def get_calendar():
time_range = (0, time.time()) wxid = request.json.get('wxid')
world_cloud_data = analysis.calendar_chart(contact.wxid, time_range=time_range) time_range = request.json.get('time_range',[])
world_cloud_data = analysis.calendar_chart(wxid, time_range=time_range)
return jsonify(world_cloud_data) return jsonify(world_cloud_data)
@app.route('/message_counter') @app.route('/message_counter', methods=['POST'])
def get_counter(): 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) data = analysis.sender(contact.wxid, time_range=time_range, my_name=Me().name, ta_name=contact.remark)
return jsonify(data) return jsonify(data)