From 12b14316ce7fe54d1930096561803559dd8deb3f Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Tue, 21 Nov 2023 22:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=BC=E5=87=BAHTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 47 +- app/DataBase/msg.py | 12 +- app/DataBase/output_pc.py | 232 + app/data/html/0.html | 290 -- app/data/html/1.html | 707 --- app/data/html/2.html | 1228 ----- app/data/html/3.html | 652 --- app/data/html/4.html | 1232 ----- app/data/html/5.html | 7567 ------------------------------ app/data/html/6.html | 1344 ------ app/data/html/index.html | 252 - app/person.py | 3 + app/ui_pc/chat/chat_info.py | 1 + app/ui_pc/contact/contactInfo.py | 13 +- 14 files changed, 279 insertions(+), 13301 deletions(-) delete mode 100644 app/data/html/0.html delete mode 100644 app/data/html/1.html delete mode 100644 app/data/html/2.html delete mode 100644 app/data/html/3.html delete mode 100644 app/data/html/4.html delete mode 100644 app/data/html/5.html delete mode 100644 app/data/html/6.html delete mode 100644 app/data/html/index.html diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e734d87..9a2cc1b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,12 +4,21 @@ - @@ -684,7 +692,8 @@ - @@ -708,17 +717,17 @@ file://$PROJECT_DIR$/app/person.py - 100 + 103 file://$PROJECT_DIR$/app/person.py - 98 + 101 file://$PROJECT_DIR$/app/person.py - 99 + 102 diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index e15b142..3232526 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -49,10 +49,14 @@ def get_messages(username_): ''' result = [] for cur in cursor: - cur.execute(sql, [username_]) - result_ = cur.fetchall() - # print(len(result)) - result += result_ + try: + lock.acquire(True) + cur.execute(sql, [username_]) + result_ = cur.fetchall() + # print(len(result)) + result += result_ + finally: + lock.release() result.sort(key=lambda x: x[5]) return result diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index c1e3940..b46f312 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -5,6 +5,7 @@ from PyQt5.QtCore import pyqtSignal, QThread from . import msg from ..log import log +from ..person import MePC if not os.path.exists('./data/聊天记录'): os.mkdir('./data/聊天记录') @@ -24,6 +25,7 @@ class Output(QThread): def __init__(self, contact, parent=None, type_=DOCX): super().__init__(parent) + self.last_timestamp = 0 self.sec = 2 # 默认1000秒 self.contact = contact self.ta_username = contact.wxid @@ -51,9 +53,239 @@ class Output(QThread): df.to_csv(filename, encoding='utf-8') self.okSignal.emit('ok') + def to_html(self): + origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}" + if not os.path.exists(origin_docx_path): + os.mkdir(origin_docx_path) + messages = msg.get_messages(self.contact.wxid) + filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html" + f = open(filename, 'w', encoding='utf-8') + html_head = ''' + + + + + Title + + + +
+
+ ''' + f.write(html_head) + MePC().avatar.save(os.path.join(origin_docx_path, 'myhead.png')) + self.contact.avatar.save(os.path.join(origin_docx_path, 'tahead.png')) + for message in messages: + type_ = message[2] + str_content = message[7] + str_time = message[8] + # print(type_, type(type_)) + is_send = message[4] + avatar = MePC().avatar_path if is_send else self.contact.avatar_path + timestamp = message[5] + if type_ == 1: + if self.is_5_min(timestamp): + f.write( + f''' +
{str_time}
+ ''' + ) + if is_send: + f.write( + f''' +
+
{str_content}
+
+ +
+
+ ''' + ) + else: + f.write( + f''' +
+
+ +
+
{str_content} +
+
+ ''' + ) + html_end = ''' + +
+
+ + + ''' + f.write(html_end) + f.close() + self.okSignal.emit('ok') + + def is_5_min(self, timestamp): + if abs(timestamp - self.last_timestamp) > 300: + self.last_timestamp = timestamp + + return True + return False + def run(self): if self.output_type == self.DOCX: return elif self.output_type == self.CSV: # print("线程导出csv") self.to_csv(self.ta_username, "path") + elif self.output_type == self.HTML: + self.to_html() diff --git a/app/data/html/0.html b/app/data/html/0.html deleted file mode 100644 index d377192..0000000 --- a/app/data/html/0.html +++ /dev/null @@ -1,290 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

- 未眠人 -

-

- 二零二二年度报告 -

- -
-
- - - - - -
-
- avatar -
-
-
-

- 小学生 -

-
-
-
-

- 我们第一次聊天发生在 -

-

- 2023-09-18 20:39:08 -

-
- - 距今已有 - - - 626 天 - - - 6 时 - - - 26 分 - - - 26 秒 - -
-
-
-
-
-
-
-
- 进入 -
-
-
-
-
-
-
-
- - - - - - - \ No newline at end of file diff --git a/app/data/html/1.html b/app/data/html/1.html deleted file mode 100644 index 9e2e3a0..0000000 --- a/app/data/html/1.html +++ /dev/null @@ -1,707 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Norcy
-
-
-
-
进入
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

过去的日子里

-

我们一共发送了 - 91835条消息

-

总计 - 388161

-

 

-

- 我们的聊天似乎没有规律

-

- 八月份我们一共发送了11629条信息

-

- 对你的话说不完

-

 

-

但 - 六月份只有2139条信息

-

 大概,我们有时候也想静静

-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/app/data/html/2.html b/app/data/html/2.html deleted file mode 100644 index df93a6f..0000000 --- a/app/data/html/2.html +++ /dev/null @@ -1,1228 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

二零二二

-

你说的最多的是

-
-
-
-
-
-
-
- - - - -
-
- 5 - 9 - 5 - -
-
-
-
    -
  • -
    -
    我 - 喜欢这个衣服 -
    -
    -
    - 它就是好看啊
    -
    -
  • -
  • -
    -
    我还是 - 喜欢大城市 -
    -
    -
    - 很繁华
    -
    -
  • -
  • -
    -
    也不知道你为啥不 - 喜欢 -
    -
    -
    - 也没有吧
    -
    -
  • -
  • -
    -
    但是我 - 喜欢火锅 -
    -
    -
    - 吃,使劲吃
    -
    -
  • -
-
-
-
-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/app/data/html/3.html b/app/data/html/3.html deleted file mode 100644 index 1d17efd..0000000 --- a/app/data/html/3.html +++ /dev/null @@ -1,652 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-

在TA的音乐品味中 

-

也藏着高冷的一面 

-

这首有些小众的 

-

- 《夏天的味道(Cover 石头剪刀布)》

-

在今年TA一共听了 - 15次 

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-

 

-

2022-03-12 - 04:36:10 

-

- 这么晚了你们还在聊天 -

-

这天一定有你们 - 难忘的回忆 吧 -

-
-

 

-

你们都是 - 夜猫子 

-

- 凌晨01:00 -

-

你们共发送了 - 8517 条信息 -

- -
- -
- -
-

2022-03-12 04:36:10 

- -
- - - - - -
-
- avatar: -
-
-
-

- : 无语了也不知道我这大晚上干嘛不睡觉,生生接住了这波狗粮

-
-
- - - - - - -
-
-

- 快睡觉 :

-
-
-
- avatar: -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - - - - -
-
-
- - - \ No newline at end of file diff --git a/app/data/html/4.html b/app/data/html/4.html deleted file mode 100644 index 472bb91..0000000 --- a/app/data/html/4.html +++ /dev/null @@ -1,1232 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-

2018

-

TA在网易云音乐听到的最多的歌词是

-
-
-
-
-
-
-
- - - - - - -
-
- 7 - 6 - 5 - -
-
-
-
    -
  • -
    -
    - 天使在人间是该藏好翅膀 -
    -
    -
    - Tank《专属天使》
    -
    -
  • -
  • -
    -
    你是魔鬼中的 - 天使, 所以送我心碎的方式 -
    -
    -
    - 田馥甄《魔鬼中的天使》
    -
    -
  • -
  • -
    -
    请 - 天使来唱歌, 当我很不快乐 -
    -
    -
    - S.H.E《天使在唱歌》
    -
    -
  • -
  • -
    -
    谁人又为 - 天使忧愁 -
    -
    -
    - 梁汉文《七友》
    -
    -
  • -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

- 5月1日

-

大概是很特别的一天

-

这一天里

-

你们的对话充满了 - 积极情感

-

从早上9点 到晚上12点

-

你们共发送了 - 2294 - 条信息 -

-

信息数量 - 全年最高 -

-
-
-
- -
-
-
-
-
- - - - - -
-
-
- - - \ No newline at end of file diff --git a/app/data/html/5.html b/app/data/html/5.html deleted file mode 100644 index e3a95ff..0000000 --- a/app/data/html/5.html +++ /dev/null @@ -1,7567 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

1月29日

-

这一天Ta走了

-

- 17498

-

 在你好友排名 - 第一

-

 

-

你知道

-

- 这一天Ta去哪了吗?

-
-
-
-
-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/app/data/html/6.html b/app/data/html/6.html deleted file mode 100644 index 1e42b5f..0000000 --- a/app/data/html/6.html +++ /dev/null @@ -1,1344 +0,0 @@ - - - - - - - - - - - 年度聊天报告 - - - - - - - - - - - - - - -
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -

这一年

-

我们有 - 230天在聊天

-

有你在的日子里

-

都很有 - 意义

-
-

这一年

-

一共发送了 - 3454个表情包

-

Ta最常用的表情包是 -

- -

一共 - 184次 -

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - - - - - - - - \ No newline at end of file diff --git a/app/data/html/index.html b/app/data/html/index.html deleted file mode 100644 index dfb2b00..0000000 --- a/app/data/html/index.html +++ /dev/null @@ -1,252 +0,0 @@ - - - - - - - - - - - - - -
-
-
    -
  •  
  • -
  •  
  • -
  •  
  • -
  •  
  • -
  •  
  • -
  •  
  • -
  •  
  • -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
-
- - - - \ No newline at end of file diff --git a/app/person.py b/app/person.py index e52aa89..1e67791 100644 --- a/app/person.py +++ b/app/person.py @@ -55,6 +55,7 @@ def singleton(cls): class MePC: def __init__(self): self.avatar = QPixmap(Icon.Default_avatar_path) + self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg' self.wxid = '' self.wx_dir = '' self.name = '' @@ -82,6 +83,7 @@ class ContactPC: self.smallHeadImgUrl = contact_info.get('smallHeadImgUrl') self.smallHeadImgBLOG = b'' self.avatar = QPixmap() + self.avatar_path = 'D:\Project\Python\WeChatMsg\\app\data\icons\default_avatar.svg' def set_avatar(self, img_bytes): if not img_bytes: @@ -91,6 +93,7 @@ class ContactPC: self.avatar.loadFromData(img_bytes, format='PNG') else: self.avatar.loadFromData(img_bytes, format='jfif') + self.avatar.scaled(60, 60, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) diff --git a/app/ui_pc/chat/chat_info.py b/app/ui_pc/chat/chat_info.py index d5a7958..dd2bf1e 100644 --- a/app/ui_pc/chat/chat_info.py +++ b/app/ui_pc/chat/chat_info.py @@ -100,6 +100,7 @@ class ChatInfo(QWidget): ) self.chat_window.add_message_item(bubble_message, 0) elif type_ == 3: + return if self.is_5_min(timestamp): time_message = Notice(self.last_str_time) self.last_str_time = str_time diff --git a/app/ui_pc/contact/contactInfo.py b/app/ui_pc/contact/contactInfo.py index 107977c..afc7e36 100644 --- a/app/ui_pc/contact/contactInfo.py +++ b/app/ui_pc/contact/contactInfo.py @@ -114,12 +114,13 @@ class ContactInfo(QWidget, Ui_Form): self.outputThread = Output(self.contact, type_=Output.CSV) print('导出csv') elif self.sender() == self.toHtmlAct: - print('功能暂未实现') - QMessageBox.warning(self, - "别急别急", - "马上就实现该功能" - ) - return + self.outputThread = Output(self.contact, type_=Output.HTML) + # print('功能暂未实现') + # QMessageBox.warning(self, + # "别急别急", + # "马上就实现该功能" + # ) + # return self.outputThread.progressSignal.connect(self.output_progress) self.outputThread.rangeSignal.connect(self.set_progressBar_range) self.outputThread.okSignal.connect(self.hide_progress_bar)