词云新增自定义词

This commit is contained in:
shuaikangzhou 2024-02-17 21:34:46 +08:00
parent 3d77a01748
commit 6feb0fc490
14 changed files with 155 additions and 81 deletions

View File

@ -72,6 +72,7 @@ def wordcloud_(wxid, time_range=None):
def get_wordcloud(text):
total_msg_len = len(text)
jieba.load_userdict('./app/data/new_words.txt')
# 使用jieba进行分词并加入停用词
words = jieba.cut(text)
# 统计词频

View File

@ -23,6 +23,10 @@ about = f'''
# 数据存放文件路径
info_file_path = './app/data/info.json' # 个人信息文件
db_dir = './app/Database/Msg'
output_dir = './data/' # 输出文件夹
INFO_FILE_PATH = './app/data/info.json' # 个人信息文件
DB_DIR = './app/Database/Msg'
OUTPUT_DIR = './data/' # 输出文件夹
# 全局参数
SEND_LOG_FLAG = True # 是否发送错误日志

View File

@ -8,7 +8,7 @@ from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox
from app.DataBase import msg_db
from app.components import ScrollBar
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.ui.menu.export_time_range import TimeRangeDialog
from .exportUi import Ui_Dialog
from app.util.exporter.output import Output
@ -174,7 +174,7 @@ class ExportDialog(QDialog, Ui_Dialog):
reply.setIcon(QMessageBox.Information)
reply.setWindowTitle('OK')
reply.setText(
f"导出聊天记录成功\n{output_dir}目录下(跟exe文件在一起)\n{os.path.normpath(os.path.join(os.getcwd(), output_dir))}")
f"导出聊天记录成功\n{OUTPUT_DIR}目录下(跟exe文件在一起)\n{os.path.normpath(os.path.join(os.getcwd(), OUTPUT_DIR))}")
reply.addButton("确认", QMessageBox.AcceptRole)
reply.addButton("取消", QMessageBox.RejectRole)
api = reply.exec_()

View File

@ -26,7 +26,7 @@ from app.ui.home.home_window import HomeWindow
from .menu.export import ExportDialog
from app.util.exporter.output import Output
from ..components.QCursorGif import QCursorGif
from ..config import info_file_path, db_dir
from ..config import INFO_FILE_PATH, DB_DIR
from ..log import logger
from ..person import Me
@ -304,8 +304,8 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow, QCursorGif):
self.action_update.setIcon(Icon.Update_Icon)
def load_data(self, flag=True):
if os.path.exists(info_file_path):
with open(info_file_path, 'r', encoding='utf-8') as f:
if os.path.exists(INFO_FILE_PATH):
with open(INFO_FILE_PATH, 'r', encoding='utf-8') as f:
dic = json.loads(f.read())
wxid = dic.get('wxid')
if wxid:
@ -355,7 +355,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow, QCursorGif):
close_db()
import shutil
try:
shutil.rmtree(db_dir)
shutil.rmtree(DB_DIR)
except:
pass
return
@ -371,7 +371,7 @@ class MainWinController(QMainWindow, mainwindow.Ui_MainWindow, QCursorGif):
close_db()
import shutil
try:
shutil.rmtree(db_dir)
shutil.rmtree(DB_DIR)
except:
pass
QMessageBox.critical(self, "数据库错误", "请重启电脑后重试")

View File

@ -11,7 +11,7 @@ from app.DataBase import micro_msg_db, misc_db
from app.util.exporter.output import Output
from app.components import ScrollBar
from app.components.export_contact_item import ContactQListWidgetItem
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.person import Contact
from app.ui.menu.exportUi import Ui_Dialog
from app.ui.menu.export_time_range import TimeRangeDialog
@ -213,7 +213,7 @@ class ExportDialog(QDialog, Ui_Dialog):
reply = QMessageBox(self)
reply.setIcon(QMessageBox.Information)
reply.setWindowTitle('OK')
reply.setText(f"导出聊天记录成功\n{output_dir}目录下(跟exe文件在一起)\n{os.path.normpath(os.path.join(os.getcwd(),output_dir))}")
reply.setText(f"导出聊天记录成功\n{OUTPUT_DIR}目录下(跟exe文件在一起)\n{os.path.normpath(os.path.join(os.getcwd(), OUTPUT_DIR))}")
reply.addButton("确认", QMessageBox.AcceptRole)
reply.addButton("取消", QMessageBox.RejectRole)
api = reply.exec_()

View File

@ -11,7 +11,7 @@ from PyQt5.QtWidgets import QWidget, QMessageBox, QFileDialog
from app.DataBase import msg_db, misc_db, close_db
from app.DataBase.merge import merge_databases, merge_MediaMSG_databases
from app.components.QCursorGif import QCursorGif
from app.config import info_file_path, db_dir
from app.config import INFO_FILE_PATH, DB_DIR
from app.decrypt import get_wx_info, decrypt
from app.log import logger
from app.util import path
@ -186,7 +186,7 @@ class DecryptControl(QWidget, decryptUi.Ui_Dialog, QCursorGif):
try:
os.makedirs('./app/data', exist_ok=True)
with open(info_file_path, "w", encoding="utf-8") as f:
with open(INFO_FILE_PATH, "w", encoding="utf-8") as f:
json.dump(dic, f, ensure_ascii=False, indent=4)
except:
with open('./info.json', 'w', encoding='utf-8') as f:
@ -216,7 +216,7 @@ class DecryptThread(QThread):
msg_db.close()
# micro_msg_db.close()
# hard_link_db.close()
output_dir = db_dir
output_dir = DB_DIR
os.makedirs(output_dir, exist_ok=True)
tasks = []
if os.path.exists(self.db_path):
@ -246,14 +246,14 @@ class DecryptThread(QThread):
self.signal.emit(str(i))
# print(self.db_path)
# 目标数据库文件
target_database = os.path.join(db_dir, 'MSG.db')
target_database = os.path.join(DB_DIR, 'MSG.db')
# 源数据库文件列表
source_databases = [os.path.join(db_dir, f"MSG{i}.db") for i in range(1, 50)]
source_databases = [os.path.join(DB_DIR, f"MSG{i}.db") for i in range(1, 50)]
import shutil
if os.path.exists(target_database):
os.remove(target_database)
try:
shutil.copy2(os.path.join(db_dir, 'MSG0.db'), target_database) # 使用一个数据库文件作为模板
shutil.copy2(os.path.join(DB_DIR, 'MSG0.db'), target_database) # 使用一个数据库文件作为模板
except FileNotFoundError:
logger.error(traceback.format_exc())
self.errorSignal.emit(True)
@ -265,13 +265,13 @@ class DecryptThread(QThread):
QMessageBox.critical("错误", "数据库不存在\n请检查微信版本是否为最新")
# 音频数据库文件
target_database = os.path.join(db_dir,'MediaMSG.db')
target_database = os.path.join(DB_DIR, 'MediaMSG.db')
# 源数据库文件列表
if os.path.exists(target_database):
os.remove(target_database)
source_databases = [os.path.join(db_dir,f"MediaMSG{i}.db") for i in range(1, 50)]
source_databases = [os.path.join(DB_DIR, f"MediaMSG{i}.db") for i in range(1, 50)]
try:
shutil.copy2(os.path.join(db_dir,'MediaMSG0.db'), target_database) # 使用一个数据库文件作为模板
shutil.copy2(os.path.join(DB_DIR, 'MediaMSG0.db'), target_database) # 使用一个数据库文件作为模板
except FileNotFoundError:
logger.error(traceback.format_exc())
self.errorSignal.emit(True)

View File

@ -2,7 +2,7 @@ import json
import os.path
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QWidget, QMessageBox
from app.config import SEND_LOG_FLAG
from .settingUi import Ui_Form
Stylesheet = """
@ -64,6 +64,12 @@ QCheckBox::indicator:checked{
"""
def set_SEND_LOG_FLAG(flag):
# noinspection PyGlobalUndefined
global SEND_LOG_FLAG
SEND_LOG_FLAG = flag
class SettingControl(QWidget, Ui_Form):
def __init__(self, parent=None):
@ -72,6 +78,7 @@ class SettingControl(QWidget, Ui_Form):
self.setupUi(self)
self.btn_addstopword.clicked.connect(self.add_stopwords)
self.btn_addnewword_2.clicked.connect(self.add_new_words)
self.init_ui()
self.read_data()
@ -82,13 +89,17 @@ class SettingControl(QWidget, Ui_Form):
def set_error_log(self):
if self.checkBox_send_error_log.isChecked():
self.label_error_log.setText('')
set_SEND_LOG_FLAG(True)
else:
self.label_error_log.setText('')
set_SEND_LOG_FLAG(False)
print('SEND_LOG_FLAG:', SEND_LOG_FLAG)
def read_data(self):
os.makedirs('./app/data', exist_ok=True)
stopwords = ['裂开', '苦涩', '叹气', '凋谢', '让我看看', '', '奋斗', '疑问', '擦汗', '抠鼻', '鄙视', '勾引',
'奸笑', '嘿哈', '捂脸', '机智', '加油', '吃瓜', '尴尬', '炸弹', '旺柴']
new_words = ['YYDS', '666', '显眼包', '遥遥领先']
if os.path.exists('./app/data/stopwords.txt'):
with open('./app/data/stopwords.txt', 'r', encoding='utf-8') as f:
stopwords = set(f.read().splitlines())
@ -98,6 +109,15 @@ class SettingControl(QWidget, Ui_Form):
stopwords = '\n'.join(stopwords)
with open('./app/data/stopwords.txt', 'w', encoding='utf-8') as f:
f.write(stopwords)
if os.path.exists('./app/data/new_words.txt'):
with open('./app/data/new_words.txt', 'r', encoding='utf-8') as f:
stopwords = set(f.read().splitlines())
self.plainTextEdit_newword.setPlainText(' '.join(new_words))
else:
self.plainTextEdit_newword.setPlainText(' '.join(new_words))
stopwords = '\n'.join(stopwords)
with open('./app/data/new_words.txt', 'w', encoding='utf-8') as f:
f.write(stopwords)
def add_stopwords(self):
text = self.plainTextEdit.toPlainText()
@ -105,3 +125,10 @@ class SettingControl(QWidget, Ui_Form):
with open('./app/data/stopwords.txt', 'w', encoding='utf-8') as f:
f.write(stopwords)
QMessageBox.about(self, "添加成功", "停用词添加成功")
def add_new_words(self):
text = self.plainTextEdit_newword.toPlainText()
new_words = '\n'.join(text.split())
with open('./app/data/new_words.txt', 'w', encoding='utf-8') as f:
f.write(new_words)
QMessageBox.about(self, "添加成功", "自定义词添加成功")

View File

@ -14,9 +14,9 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(587, 573)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Form)
self.verticalLayout_2.setObjectName("verticalLayout_2")
Form.resize(638, 696)
self.verticalLayout_6 = QtWidgets.QVBoxLayout(Form)
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.scrollArea = QtWidgets.QScrollArea(Form)
self.scrollArea.setFrameShape(QtWidgets.QFrame.NoFrame)
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
@ -25,7 +25,7 @@ class Ui_Form(object):
self.scrollArea.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 552, 555))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -20, 595, 728))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_3.setObjectName("verticalLayout_3")
@ -68,6 +68,46 @@ class Ui_Form(object):
self.verticalLayout.addLayout(self.horizontalLayout)
self.verticalLayout_4.addLayout(self.verticalLayout)
self.verticalLayout_3.addWidget(self.widget)
self.widget_3 = QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.widget_3.setStyleSheet("QWidget{\n"
" background-color:rgb(251,251,251);\n"
" border-radius: 10px;\n"
"}\n"
"\n"
"QPushButton{\n"
" background-color: rgb(250,252,253);\n"
" border-radius: 5px;\n"
" padding: 8px;\n"
" border-right: 2px solid #888888; /* 按钮边框2px宽白色 */\n"
" border-bottom: 2px solid #888888; /* 按钮边框2px宽白色 */\n"
" border-left: 1px solid #ffffff; /* 按钮边框2px宽白色 */\n"
" border-top: 1px solid #ffffff; /* 按钮边框2px宽白色 */\n"
"}\n"
"QPushButton:hover { \n"
" background-color: lightgray;\n"
"}")
self.widget_3.setObjectName("widget_3")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.widget_3)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.label_2 = QtWidgets.QLabel(self.widget_3)
self.label_2.setObjectName("label_2")
self.verticalLayout_2.addWidget(self.label_2)
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.plainTextEdit_newword = QtWidgets.QPlainTextEdit(self.widget_3)
self.plainTextEdit_newword.setFrameShape(QtWidgets.QFrame.Box)
self.plainTextEdit_newword.setFrameShadow(QtWidgets.QFrame.Sunken)
self.plainTextEdit_newword.setPlainText("")
self.plainTextEdit_newword.setObjectName("plainTextEdit_newword")
self.horizontalLayout_3.addWidget(self.plainTextEdit_newword)
self.btn_addnewword_2 = QtWidgets.QPushButton(self.widget_3)
self.btn_addnewword_2.setObjectName("btn_addnewword_2")
self.horizontalLayout_3.addWidget(self.btn_addnewword_2)
self.verticalLayout_2.addLayout(self.horizontalLayout_3)
self.verticalLayout_5.addLayout(self.verticalLayout_2)
self.verticalLayout_3.addWidget(self.widget_3)
self.widget_2 = QtWidgets.QWidget(self.scrollAreaWidgetContents)
self.widget_2.setStyleSheet("QWidget{\n"
" background-color:rgb(251,251,251);\n"
@ -90,22 +130,22 @@ class Ui_Form(object):
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.widget_2)
self.horizontalLayout_2.setContentsMargins(9, -1, -1, -1)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.commandLinkButton = QtWidgets.QCommandLinkButton(self.widget_2)
self.commandLinkButton.setEnabled(True)
self.commandLinkButton.setTabletTracking(False)
self.commandLinkButton.setFocusPolicy(QtCore.Qt.StrongFocus)
self.commandLinkButton.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.commandLinkButton.setToolTipDuration(-1)
self.commandLinkButton.setLayoutDirection(QtCore.Qt.LeftToRight)
self.commandLinkButton.setAutoFillBackground(False)
self.commandLinkButton.setCheckable(False)
self.commandLinkButton.setChecked(False)
self.commandLinkButton.setAutoRepeat(False)
self.commandLinkButton.setAutoExclusive(False)
self.commandLinkButton.setAutoDefault(False)
self.commandLinkButton.setDefault(False)
self.commandLinkButton.setObjectName("commandLinkButton")
self.horizontalLayout_2.addWidget(self.commandLinkButton)
self.commandLinkButton_send_error_log = QtWidgets.QCommandLinkButton(self.widget_2)
self.commandLinkButton_send_error_log.setEnabled(True)
self.commandLinkButton_send_error_log.setTabletTracking(False)
self.commandLinkButton_send_error_log.setFocusPolicy(QtCore.Qt.StrongFocus)
self.commandLinkButton_send_error_log.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.commandLinkButton_send_error_log.setToolTipDuration(-1)
self.commandLinkButton_send_error_log.setLayoutDirection(QtCore.Qt.LeftToRight)
self.commandLinkButton_send_error_log.setAutoFillBackground(False)
self.commandLinkButton_send_error_log.setCheckable(False)
self.commandLinkButton_send_error_log.setChecked(False)
self.commandLinkButton_send_error_log.setAutoRepeat(False)
self.commandLinkButton_send_error_log.setAutoExclusive(False)
self.commandLinkButton_send_error_log.setAutoDefault(False)
self.commandLinkButton_send_error_log.setDefault(False)
self.commandLinkButton_send_error_log.setObjectName("commandLinkButton_send_error_log")
self.horizontalLayout_2.addWidget(self.commandLinkButton_send_error_log)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem)
self.label_error_log = QtWidgets.QLabel(self.widget_2)
@ -120,7 +160,7 @@ class Ui_Form(object):
self.checkBox_send_error_log = QtWidgets.QCheckBox(self.widget_2)
self.checkBox_send_error_log.setText("")
self.checkBox_send_error_log.setIconSize(QtCore.QSize(64, 64))
self.checkBox_send_error_log.setChecked(False)
self.checkBox_send_error_log.setChecked(True)
self.checkBox_send_error_log.setObjectName("checkBox_send_error_log")
self.horizontalLayout_2.addWidget(self.checkBox_send_error_log)
self.verticalLayout_3.addWidget(self.widget_2)
@ -138,7 +178,7 @@ class Ui_Form(object):
self.radioButton.setObjectName("radioButton")
self.verticalLayout_3.addWidget(self.radioButton)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_2.addWidget(self.scrollArea)
self.verticalLayout_6.addWidget(self.scrollArea)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
@ -149,9 +189,11 @@ class Ui_Form(object):
self.label.setText(_translate("Form", "文本框里输入年度报告词云停用词,每个词之间用空格隔开"))
self.plainTextEdit.setPlainText(_translate("Form", "哈哈哈 发呆"))
self.btn_addstopword.setText(_translate("Form", "添加停用词"))
self.commandLinkButton.setText(_translate("Form", "收集错误日志"))
self.commandLinkButton.setDescription(_translate("Form", "收集错误信息以帮助改进"))
self.label_error_log.setText(_translate("Form", ""))
self.label_2.setText(_translate("Form", "文本框里输入年度报告词云自定义词,每个词之间用空格隔开"))
self.btn_addnewword_2.setText(_translate("Form", "添加自定义词"))
self.commandLinkButton_send_error_log.setText(_translate("Form", "收集错误日志"))
self.commandLinkButton_send_error_log.setDescription(_translate("Form", "收集错误信息以帮助改进"))
self.label_error_log.setText(_translate("Form", ""))
self.checkBox_2.setText(_translate("Form", "CheckBox"))
self.checkBox.setText(_translate("Form", "CheckBox"))
self.commandLinkButton_2.setText(_translate("Form", "CommandLinkButton"))

View File

@ -8,10 +8,10 @@ import filecmp
from PyQt5.QtCore import pyqtSignal, QThread
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.person import Me, Contact
os.makedirs(os.path.join(output_dir, '聊天记录'), exist_ok=True)
os.makedirs(os.path.join(OUTPUT_DIR, '聊天记录'), exist_ok=True)
def set_global_font(doc, font_name):
@ -104,7 +104,7 @@ class ExporterBase(QThread):
self.last_timestamp = 0
self.time_range = time_range
self.messages = messages
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
makedirs(origin_path)
def run(self):

View File

@ -3,13 +3,13 @@ import os
from app.DataBase import msg_db
from app.util.exporter.exporter import ExporterBase
from app.config import output_dir
from app.config import OUTPUT_DIR
class CSVExporter(ExporterBase):
def to_csv(self):
print(f"【开始导出 CSV {self.contact.remark}")
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
os.makedirs(origin_path, exist_ok=True)
filename = os.path.join(origin_path,f"{self.contact.remark}_utf8.csv")
columns = ['localId', 'TalkerId', 'Type', 'SubType',

View File

@ -12,7 +12,7 @@ from docxcompose.composer import Composer
from app.DataBase import msg_db, hard_link_db
from app.util.exporter.exporter import ExporterBase, escape_js_and_html
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.log import logger
from app.person import Me
from app.util.compress_content import parser_reply, share_card, music_share
@ -76,7 +76,7 @@ class DocxExporter(ExporterBase):
run = content.paragraphs[0].add_run()
str_content = escape_js_and_html(str_content)
image_path = hard_link_db.get_image(str_content, BytesExtra, thumb=True)
base_path = os.path.join(output_dir, '聊天记录', self.contact.remark, 'image')
base_path = os.path.join(OUTPUT_DIR, '聊天记录', self.contact.remark, 'image')
if not os.path.exists(os.path.join(Me().wx_dir, image_path)):
image_thumb_path = hard_link_db.get_image(str_content, BytesExtra, thumb=False)
if not os.path.exists(os.path.join(Me().wx_dir, image_thumb_path)):
@ -239,7 +239,7 @@ class DocxExporter(ExporterBase):
return content_cell
def music_share(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
is_send = message[4]
timestamp = message[5]
content = music_share(message[11])
@ -282,7 +282,7 @@ class DocxExporter(ExporterBase):
app_logo = ''
def merge_docx(self, conRemark, n):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录')
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录')
all_file_path = []
for i in range(n):
file_name = f"{conRemark}{i}.docx"
@ -305,7 +305,7 @@ class DocxExporter(ExporterBase):
def export(self):
print(f"【开始导出 DOCX {self.contact.remark}")
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages(self.contact.wxid, time_range=self.time_range)
Me().save_avatar(os.path.join(origin_path, 'avatar', f'{Me().wxid}.png'))
if self.contact.is_chatroom:

View File

@ -8,7 +8,7 @@ from PyQt5.QtCore import pyqtSignal, QThread
from app.DataBase import msg_db, hard_link_db, media_msg_db
from app.util.exporter.exporter import ExporterBase, escape_js_and_html
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.log import logger
from app.person import Me
from app.util import path
@ -45,7 +45,7 @@ class HtmlExporter(ExporterBase):
)
def image(self, doc, message):
base_path = os.path.join(output_dir, '聊天记录', self.contact.remark, 'image')
base_path = os.path.join(OUTPUT_DIR, '聊天记录', self.contact.remark, 'image')
type_ = message[2]
str_content = message[7]
str_time = message[8]
@ -63,7 +63,7 @@ class HtmlExporter(ExporterBase):
)
def audio(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
str_content = message[7]
str_time = message[8]
is_send = message[4]
@ -99,7 +99,7 @@ class HtmlExporter(ExporterBase):
)
def file(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
bytesExtra = message[10]
compress_content = message[11]
str_time = message[8]
@ -170,7 +170,7 @@ class HtmlExporter(ExporterBase):
)
def video(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
type_ = message[2]
str_content = message[7]
str_time = message[8]
@ -211,7 +211,7 @@ class HtmlExporter(ExporterBase):
)
def music_share(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
is_send = message[4]
timestamp = message[5]
content = music_share(message[11])
@ -232,7 +232,7 @@ class HtmlExporter(ExporterBase):
)
def share_card(self, doc, message):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
is_send = message[4]
timestamp = message[5]
bytesExtra = message[10]
@ -299,7 +299,7 @@ class HtmlExporter(ExporterBase):
def export(self):
print(f"【开始导出 HTML {self.contact.remark}")
messages = msg_db.get_messages(self.contact.wxid, time_range=self.time_range)
filename = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark,
filename = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark,
f'{self.contact.remark}.html')
file_path = './app/resources/data/template.html'
if not os.path.exists(file_path):
@ -381,7 +381,7 @@ class OutputMedia(QThread):
self.contact = contact
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 34)
for message in messages:
is_send = message[4]
@ -410,7 +410,7 @@ class OutputEmoji(QThread):
self.contact = contact
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 47)
for message in messages:
str_content = message[7]
@ -447,9 +447,9 @@ class OutputImage(QThread):
print("图片导出完成")
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 3)
base_path = os.path.join(output_dir, '聊天记录', self.contact.remark, 'image')
base_path = os.path.join(OUTPUT_DIR, '聊天记录', self.contact.remark, 'image')
for message in messages:
str_content = message[7]
BytesExtra = message[10]
@ -489,7 +489,7 @@ class OutputImageChild(QThread):
self.messages = messages
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
for message in self.messages:
str_content = message[7]
BytesExtra = message[10]

View File

@ -2,7 +2,7 @@ import os
from app.DataBase import msg_db
from app.util.exporter.exporter import ExporterBase
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.util.compress_content import parser_reply, share_card
@ -112,7 +112,7 @@ class TxtExporter(ExporterBase):
def export(self):
# 实现导出为txt的逻辑
print(f"【开始导出 TXT {self.contact.remark}")
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
os.makedirs(origin_path, exist_ok=True)
filename = os.path.join(origin_path, self.contact.remark+'.txt')
messages = msg_db.get_messages(self.contact.wxid, time_range=self.time_range)

View File

@ -15,14 +15,14 @@ from app.util.exporter.exporter_docx import DocxExporter
from app.util.exporter.exporter_html import HtmlExporter
from app.util.exporter.exporter_txt import TxtExporter
from app.DataBase.hard_link import decodeExtraBuf
from app.config import output_dir
from app.config import OUTPUT_DIR
from app.DataBase.package_msg import PackageMsg
from app.DataBase import media_msg_db, hard_link_db, micro_msg_db, msg_db
from app.log import logger
from app.person import Me
from app.util.image import get_image
os.makedirs(os.path.join(output_dir, '聊天记录'), exist_ok=True)
os.makedirs(os.path.join(OUTPUT_DIR, '聊天记录'), exist_ok=True)
class Output(QThread):
@ -81,7 +81,7 @@ class Output(QThread):
@return:
"""
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录')
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录')
os.makedirs(origin_path, exist_ok=True)
filename = QFileDialog.getSaveFileName(None, "save file", os.path.join(os.getcwd(), 'messages.csv'),
"csv files (*.csv);;all files(*.*)")
@ -169,7 +169,7 @@ class Output(QThread):
def merge_docx(self, n):
conRemark = self.contact.remark
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', conRemark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', conRemark)
filename = f"{origin_path}/{conRemark}_{n}.docx"
if n == 10086:
# self.document.append(self.document)
@ -310,7 +310,7 @@ class OutputMedia(QThread):
self.time_range = time_range
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 34, time_range=self.time_range)
for message in messages:
is_send = message[4]
@ -337,7 +337,7 @@ class OutputEmoji(QThread):
self.time_range = time_range
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 47, time_range=self.time_range)
for message in messages:
str_content = message[7]
@ -374,9 +374,9 @@ class OutputImage(QThread):
print('图片导出完成')
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
messages = msg_db.get_messages_by_type(self.contact.wxid, 3, time_range=self.time_range)
base_path = os.path.join(output_dir,'聊天记录',self.contact.remark,'image')
base_path = os.path.join(OUTPUT_DIR, '聊天记录', self.contact.remark, 'image')
for message in messages:
str_content = message[7]
BytesExtra = message[10]
@ -406,7 +406,7 @@ class OutputImageChild(QThread):
self.time_range = time_range
def run(self):
origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark)
origin_path = os.path.join(os.getcwd(), OUTPUT_DIR, '聊天记录', self.contact.remark)
for message in self.messages:
str_content = message[7]
BytesExtra = message[10]