From 3414d74bed0445d4eea76a11ef7083dbc6b64577 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Wed, 22 Nov 2023 00:22:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DHTML=E5=8D=A1=E9=A1=BF?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 31 +- app/DataBase/msg.py | 2 +- app/DataBase/output_pc.py | 879 +++++++++++++++++++++++-------- app/ui_pc/chat/chat_info.py | 2 +- app/ui_pc/contact/contactInfo.py | 8 +- 5 files changed, 676 insertions(+), 246 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9a2cc1b..c914993 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,19 +4,10 @@ - @@ -693,7 +683,8 @@ - diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index 3232526..dd61e0d 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -67,7 +67,7 @@ def get_message_by_num(username_, local_id): from MSG where StrTalker = ? and localId < ? order by CreateTime desc - limit 30 + limit 10 ''' result = [] try: diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index b46f312..5f445a0 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -54,224 +54,7 @@ class Output(QThread): 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): @@ -281,6 +64,9 @@ class Output(QThread): return True return False + def progress(self, value): + self.progressSignal.emit(value) + def run(self): if self.output_type == self.DOCX: return @@ -288,4 +74,661 @@ class Output(QThread): # print("线程导出csv") self.to_csv(self.ta_username, "path") elif self.output_type == self.HTML: - self.to_html() + # self.to_html() + self.Child0 = ChildThread(self.contact, type_=ChildThread.HTML) + self.Child0.progressSignal.connect(self.progress) + self.Child0.rangeSignal.connect(self.rangeSignal) + self.Child0.okSignal.connect(self.okSignal) + self.Child0.run() + # self.okSignal.emit(1) + + +class ChildThread(QThread): + """ + 子线程,用于导出部分聊天记录 + """ + progressSignal = pyqtSignal(int) + rangeSignal = pyqtSignal(int) + okSignal = pyqtSignal(int) + i = 1 + CSV = 0 + DOCX = 1 + HTML = 2 + + def __init__(self, contact, parent=None, type_=DOCX): + super().__init__(parent) + self.contact = contact + self.last_timestamp = 0 + self.sec = 2 # 默认1000秒 + self.msg_id = 0 + self.output_type = type_ + + def is_5_min(self, timestamp): + if abs(timestamp - self.last_timestamp) > 300: + self.last_timestamp = timestamp + + return True + return False + + def text(self, doc, isSend, message, status): + return + + def image(self, doc, isSend, Type, content, imgPath): + return + + def emoji(self, doc, isSend, content, imgPath): + return + + def wx_file(self, doc, isSend, content, status): + return + + def retract_message(self, doc, isSend, content, status): + return + + def reply(self, doc, isSend, content, status): + return + + def pat_a_pat(self, doc, isSend, content, status): + return + + def video(self, doc, isSend, content, status, img_path): + return + + 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')) + self.rangeSignal.emit(len(messages)) + for index, message in enumerate(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] + self.progressSignal.emit(index) + 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(1) + + 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 = ''' + + + + + + Chat Records + + + +
+
+
昨天 12:35
+
你已添加了凡繁烦,现在可以开始聊天了。
+
+
+ +
+
您好,我在武汉,你可以直接送过来吗,我有时间的话,可以自己过去拿
!!!
123 +
+
+ +
+
hello
你好呀
+
+ +
+
+
+ 昨天 13:15 +
+ +
+ +
+
+
+ +
+ +
+ + +
+ + + +''' + f.write(html_end) + f.close() + self.okSignal.emit(1) + + def run(self): + if self.output_type == self.DOCX: + return + elif self.output_type == self.CSV: + return + elif self.output_type == self.HTML: + self.to_html_() diff --git a/app/ui_pc/chat/chat_info.py b/app/ui_pc/chat/chat_info.py index dd2bf1e..8ea9eaa 100644 --- a/app/ui_pc/chat/chat_info.py +++ b/app/ui_pc/chat/chat_info.py @@ -100,7 +100,7 @@ class ChatInfo(QWidget): ) self.chat_window.add_message_item(bubble_message, 0) elif type_ == 3: - return + # 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 afc7e36..402a34b 100644 --- a/app/ui_pc/contact/contactInfo.py +++ b/app/ui_pc/contact/contactInfo.py @@ -115,12 +115,7 @@ class ContactInfo(QWidget, Ui_Form): print('导出csv') elif self.sender() == self.toHtmlAct: 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) @@ -140,5 +135,6 @@ class ContactInfo(QWidget, Ui_Form): self.view_userinfo.progressBar.setProperty('value', value) def set_progressBar_range(self, value): + print('进度条范围', value) self.view_userinfo.progressBar.setVisible(True) self.view_userinfo.progressBar.setRange(0, value)