mirror of
https://github.com/LC044/WeChatMsg
synced 2025-04-28 08:48:06 +08:00
add calendar in annual_html
This commit is contained in:
parent
a4ec235450
commit
4c1d151cb9
@ -1,4 +1,5 @@
|
||||
from collections import Counter
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import QFile, QTextStream, QIODevice
|
||||
|
||||
@ -79,8 +80,21 @@ def calendar_chart(wxid, is_Annual_report=False, year='2023'):
|
||||
return False
|
||||
min_ = min(map(lambda x: x[1], calendar_data))
|
||||
max_ = max(map(lambda x: x[1], calendar_data))
|
||||
max_date = next(x[0] for x in calendar_data if x[1] == max_)
|
||||
# formatted_date = str(max_date)[:4] + '年' + str(max_date)[4:6] + '月' + str(max_date)[6:] + '日'
|
||||
date_obj = datetime.strptime(max_date, "%Y-%m-%d")
|
||||
formatted_date = date_obj.strftime("%Y年%m月%d日")
|
||||
print(formatted_date)
|
||||
|
||||
start_date_ = calendar_data[0][0]
|
||||
end_date_ = calendar_data[-1][0]
|
||||
|
||||
# 计算两个日期之间的天数差
|
||||
date1 = datetime.strptime(str(start_date_), "%Y-%m-%d")
|
||||
date2 = datetime.strptime(str(end_date_), "%Y-%m-%d")
|
||||
date_num = (date2 - date1).days + 1
|
||||
print(date_num)
|
||||
|
||||
print(start_date_, '---->', end_date_)
|
||||
if is_Annual_report:
|
||||
calendar_days = year
|
||||
@ -110,7 +124,11 @@ def calendar_chart(wxid, is_Annual_report=False, year='2023'):
|
||||
)
|
||||
)
|
||||
return {
|
||||
'chart_data': c
|
||||
'chart_data': c.dump_options_with_quotes(),
|
||||
'max_date': formatted_date,
|
||||
'max_num': str(max_),
|
||||
'date_num': str(date_num),
|
||||
'dialogs': msg_db.get_first_time_of_message(wxid) # 非年度报告使用
|
||||
}
|
||||
|
||||
|
||||
@ -197,13 +215,14 @@ class Analysis:
|
||||
if __name__ == '__main__':
|
||||
msg_db.init_database(path='../DataBase/Msg/MSG.db')
|
||||
# w = wordcloud('wxid_0o18ef858vnu22')
|
||||
w_data = wordcloud('wxid_27hqbq7vx5hf22', True, '2023')
|
||||
# w_data = wordcloud('wxid_27hqbq7vx5hf22', True, '2023')
|
||||
# print(w_data)
|
||||
# w['chart_data'].render("./data/聊天统计/wordcloud.html")
|
||||
c = calendar_chart('wxid_27hqbq7vx5hf22', False, '2023')
|
||||
c['chart_data'].render("./data/聊天统计/calendar.html")
|
||||
# c['chart_data'].render("./data/聊天统计/calendar.html")
|
||||
c['chart_data'].render("./data/calendar.html")
|
||||
# print('c:::', c)
|
||||
m = month_count('wxid_27hqbq7vx5hf22', False, '2023')
|
||||
m['chart_data'].render("./data/聊天统计/month_num.html")
|
||||
h = hour_count('wxid_27hqbq7vx5hf22')
|
||||
h['chart_data'].render("./data/聊天统计/hour_count.html")
|
||||
# m = month_count('wxid_27hqbq7vx5hf22', False, '2023')
|
||||
# m['chart_data'].render("./data/聊天统计/month_num.html")
|
||||
# h = hour_count('wxid_27hqbq7vx5hf22')
|
||||
# h['chart_data'].render("./data/聊天统计/hour_count.html")
|
||||
|
73
app/web_ui/templates/calendar.html
Normal file
73
app/web_ui/templates/calendar.html
Normal file
@ -0,0 +1,73 @@
|
||||
<!DOCTYPE html>
|
||||
<!-- saved from url=(0167)http://m2.link/c/year2018/j3POd/?uid=53899B14C24F351212F4DC92673113FC&full_screen=true&keep_status_bar=true&top_bar_bg_color=f9f9f9&status_bar_type=dark&userid=2227269 -->
|
||||
<html lang="en" class=" z-ios">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
<meta name="applicable-device" content="mobile">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, user-scalable=0, maximum-scale=1, minimum-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>年度聊天报告</title>
|
||||
<meta name="yixin-share-desc" content="点击查看,我的年度聊天报告">
|
||||
<meta name="yixin-share-image" content="https://p1.music.126.net/uLDm27B4bC_kKSD8le3WwA==/109951163754269117.jpg">
|
||||
<link rel="shortcut icon" href="http://s1.music.126.net/style/favicon.ico">
|
||||
<script src="http://share.lc044.love:8080/static/my_resource/raven.min.js"></script>
|
||||
<script type="text/javascript" src="http://share.lc044.love:8080/static/my_resource/tool.min.js"></script>
|
||||
<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>
|
||||
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts.min.js"></script>
|
||||
<script type="text/javascript" src="https://assets.pyecharts.org/assets/v5/echarts-wordcloud.min.js"></script>
|
||||
<link href="http://share.lc044.love:8080/static/my_resource/vendors.a07adb27.css" rel="stylesheet">
|
||||
<link href="http://share.lc044.love:8080/static/my_resource/main.ff465555.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="j-root" class="g-bd">
|
||||
<div class="m-app">
|
||||
<div class="m-module m-module-report z-modshow">
|
||||
<div class="m-reportcontent f-page">
|
||||
<div class="m-page m-page-01 f-page z-enter">
|
||||
<div class="bg f-page"></div>
|
||||
<div class="m-page m-page-01 f-page z-enter">
|
||||
<div class="bg f-page"></div>
|
||||
<div class="tt f-animOpac" style="font-size:30px !important">
|
||||
<h1>二零二三</h1>
|
||||
<h1>我们在这一年有这么多天在聊天</h1><br>
|
||||
</div>
|
||||
<div class="ckeywords j-anim01 z-anim">
|
||||
<div class="hands">
|
||||
<div class="hand2"></div>
|
||||
<div class="hand1"></div>
|
||||
<div class="hand3"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hand4"></div>
|
||||
<ul class="lyrics">
|
||||
<li class="itm f-animLineUp">
|
||||
<div style="transform: translateX(13.7643px);">
|
||||
<div class="line1 f-thide" style="font-size:20px !important; margin-bottom: 10px;">
|
||||
<br>今年我们一共聊了<em class="s-fcRed">{{ date_num }}</em>天,<br>在<em class="s-fcRed">{{ max_date }}</em>,我们聊得最多,有 <em class="s-fcRed">{{ max_num }}</em> 条聊天记录呢~<br>这一天,一定有什么难以忘记的故事吧!<br>你还记得吗?
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="calendar" class="chart-container" style="width:780px; height:720px;margin: auto;top:33%"></div>
|
||||
</div>
|
||||
<div class="m-btmbar"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var chart = echarts.init(document.getElementById('calendar'), 'white', {renderer: 'canvas'});
|
||||
var result = {{chart_data|safe}};
|
||||
console.log(result);
|
||||
chart.setOption(result);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
@ -68,11 +68,11 @@
|
||||
<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 id="page4" class="page">
|
||||
<iframe src="/calendar" frameborder="0" height="100%" width="100%" class="if00"></iframe>
|
||||
</div>
|
||||
<div style="background-color: #337ab7" id="page5" class="page">
|
||||
<iframe src="test" frameborder="0" id="iframe3" height="100%" width="100%" class="if00"></iframe>
|
||||
<div style="background-color: #8a6d3b" id="page5" class="page">
|
||||
<iframe src="/test" frameborder="0" id="iframe0" height="100%" width="100%" class="if00"></iframe>
|
||||
</div>
|
||||
<div style="background-color: #337ab7" id="page6" class="page">
|
||||
<iframe src="test" frameborder="0" id="iframe4" height="100%" width="100%" class="if00"></iframe>
|
||||
|
@ -68,6 +68,15 @@ def one(who):
|
||||
return render_template('wordcloud.html', **world_cloud_data, who=who)
|
||||
|
||||
|
||||
@app.route('/calendar')
|
||||
def calendar():
|
||||
wxid = contact.wxid
|
||||
world_cloud_data = analysis.calendar_chart(wxid, is_Annual_report=True)
|
||||
with open('calendar.html', 'w', encoding='utf-8') as f:
|
||||
f.write(render_template('calendar.html', **world_cloud_data))
|
||||
return render_template('calendar.html', **world_cloud_data)
|
||||
|
||||
|
||||
@app.route('/wordcloud')
|
||||
def cone():
|
||||
# wxid = contact.wxid
|
||||
|
Loading…
Reference in New Issue
Block a user