This commit is contained in:
STDquantum 2024-01-19 18:40:16 +08:00
parent 9d69f0e4cb
commit 63460e0caa

View File

@ -298,36 +298,25 @@ class HtmlExporter(ExporterBase):
print(f"【开始导出 HTML {self.contact.remark}") print(f"【开始导出 HTML {self.contact.remark}")
messages = msg_db.get_messages(self.contact.wxid, time_range=self.time_range) messages = msg_db.get_messages(self.contact.wxid, time_range=self.time_range)
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html" filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.html"
file_path = "./app/resources/data/template.html" file_path = './app/resources/data/template.html'
if not os.path.exists(file_path): if not os.path.exists(file_path):
resource_dir = getattr( resource_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
sys, "_MEIPASS", os.path.abspath(os.path.dirname(__file__)) file_path = os.path.join(resource_dir, 'app', 'resources', 'data', 'template.html')
)
file_path = os.path.join(
resource_dir, "app", "resources", "data", "template.html"
)
with open(file_path, "r", encoding="utf-8") as f: with open(file_path, "r", encoding="utf-8") as f:
content = f.read() content = f.read()
html_head, html_end = content.split("/*注意看这是分割线*/") html_head, html_end = content.split('/*注意看这是分割线*/')
f = open(filename, "w", encoding="utf-8") f = open(filename, 'w', encoding='utf-8')
html_head = html_head.replace( html_head = html_head.replace("<title>出错了</title>", f"<title>{self.contact.remark}</title>")
"<title>出错了</title>", f"<title>{self.contact.remark}</title>" html_head = html_head.replace("<p id=\"title\">出错了</p>", f"<p id=\"title\">{self.contact.remark}</p>")
)
html_head = html_head.replace(
'<p id="title">出错了</p>', f'<p id="title">{self.contact.remark}</p>'
)
f.write(html_head) f.write(html_head)
self.rangeSignal.emit(len(messages)) self.rangeSignal.emit(len(messages))
for index, message in enumerate(messages): for index, message in enumerate(messages):
type_ = message[2] type_ = message[2]
sub_type = message[3] sub_type = message[3]
timestamp = message[5] timestamp = message[5]
if ( if (type_ == 3 and self.message_types.get(3)) or (type_ == 34 and self.message_types.get(34)) or (
(type_ == 3 and self.message_types.get(3)) type_ == 47 and self.message_types.get(47)):
or (type_ == 34 and self.message_types.get(34))
or (type_ == 47 and self.message_types.get(47))
):
pass pass
else: else:
self.progressSignal.emit(1) self.progressSignal.emit(1)