From 0d979b2e629076156b91c08b7918fa501938c9ff Mon Sep 17 00:00:00 2001 From: SiYuan <863909694@qq.com> Date: Thu, 8 Feb 2024 23:39:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=91=E7=9A=84=E5=B9=B4?= =?UTF-8?q?=E5=BA=A6=E8=81=8A=E5=A4=A9=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/web_ui/templates/index.html | 506 ++++++++++++++++++++------------ app/web_ui/web.py | 18 +- 2 files changed, 337 insertions(+), 187 deletions(-) diff --git a/app/web_ui/templates/index.html b/app/web_ui/templates/index.html index 0f35d49..359a1d8 100644 --- a/app/web_ui/templates/index.html +++ b/app/web_ui/templates/index.html @@ -1,196 +1,336 @@ - - - - - - -
-
-
-
- -
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
+
+ +
+
+
+

微信年度聊天报告

+

统计、分析、回顾,记录一年的聊天时光

+ +
+
+
+

我的年度好友

+

聊天榜单

+ +
+
+

分享此页面

+
+ https://memotrace.lc044.love/
+ +
+ 点击生成我的年度聊天报告
+
+ - + }); + function createSnowflake(top, left) { + const snowflake = document.createElement('div'); + snowflake.className = 'snowflake0'; + snowflake.style.top = `${top}vh`; + snowflake.style.left = `${left}vw`; + // 设置雪花的随机大小 + const size = Math.random() * 20 + 10; // 随机大小在 10 到 30 之间 + snowflake.style.width = `${size}px`; + snowflake.style.height = `${size}px`; + document.body.appendChild(snowflake); + } + + + diff --git a/app/web_ui/web.py b/app/web_ui/web.py index b2ff1cf..7262e13 100644 --- a/app/web_ui/web.py +++ b/app/web_ui/web.py @@ -22,6 +22,7 @@ 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 = { @@ -36,10 +37,19 @@ def get_contact(wxid): contact = Contact(contact_info) return contact + @app.route("/") def index(): - # 渲染模板,并传递图表的 HTML 到模板中 - return "index.html" + contact_topN_num = msg_db.get_chatted_top_contacts(time_range=time_range, top_n=6) + contact_topN = [] + for wxid,num in contact_topN_num: + contact = get_contact(wxid) + contact_topN.append([contact,num]) + data = { + 'avatar': Me().smallHeadImgUrl, + 'contact_topN':contact_topN, + } + return render_template('index.html', **data) @app.route("/christmas/") @@ -225,7 +235,7 @@ def charts(wxid): except TypeError: first_time = '2023-01-01 00:00:00' data = { - 'wxid':wxid, + 'wxid': wxid, 'my_nickname': Me().name, 'ta_nickname': contact.remark, 'first_time': first_time @@ -236,7 +246,7 @@ def charts(wxid): @app.route('/calendar', methods=['POST']) def get_calendar(): wxid = request.json.get('wxid') - time_range = request.json.get('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)