import os import pandas as pd 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/聊天记录') class Output(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.last_timestamp = 0 self.sec = 2 # 默认1000秒 self.contact = contact self.ta_username = contact.wxid self.msg_id = 0 self.output_type = type_ self.total_num = 0 self.num = 0 @log def to_csv(self, conRemark, path): origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}" if not os.path.exists(origin_docx_path): os.mkdir(origin_docx_path) filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.csv" # columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"] columns = ['localId', 'TalkerId', 'Type', 'SubType', 'IsSender', 'CreateTime', 'Status', 'StrContent', 'StrTime'] messages = msg.get_messages(self.contact.wxid) # print() df = pd.DataFrame( data=messages, columns=columns, ) 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 = '''