WeChatMsg/app/DataBase/output_pc.py

57 lines
1.7 KiB
Python
Raw Normal View History

2023-11-15 23:53:39 +08:00
import os
import pandas as pd
2023-11-16 22:39:59 +08:00
from PyQt5.QtCore import pyqtSignal, QThread
from . import msg
from ..log import log
2023-11-15 23:53:39 +08:00
class Output(QThread):
"""
发送信息线程
"""
progressSignal = pyqtSignal(int)
rangeSignal = pyqtSignal(int)
okSignal = pyqtSignal(int)
i = 1
CSV = 0
DOCX = 1
HTML = 2
2023-11-16 22:39:59 +08:00
def __init__(self, contact, parent=None, type_=DOCX):
2023-11-15 23:53:39 +08:00
super().__init__(parent)
self.sec = 2 # 默认1000秒
2023-11-16 22:39:59 +08:00
self.contact = contact
self.ta_username = contact.wxid
2023-11-15 23:53:39 +08:00
self.msg_id = 0
self.output_type = type_
self.total_num = 0
2023-11-16 22:39:59 +08:00
self.num = 0
2023-11-15 23:53:39 +08:00
@log
def to_csv(self, conRemark, path):
2023-11-16 22:39:59 +08:00
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')
2023-11-15 23:53:39 +08:00
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")