From ce2d1457d713bd28118a7cd2368494862f862fad Mon Sep 17 00:00:00 2001 From: SiYuan <863909694@qq.com> Date: Thu, 8 Feb 2024 20:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ui/contact/export/export_dialog.py | 5 ++- app/ui/mainview.py | 3 +- app/ui/menu/export.py | 3 +- app/util/exporter/__init__.py | 0 app/{DataBase => util/exporter}/exporter.py | 6 ++-- .../exporter}/exporter_csv.py | 4 +-- .../exporter}/exporter_docx.py | 11 +++---- .../exporter}/exporter_html.py | 22 ++++++------- .../exporter}/exporter_txt.py | 4 +-- app/{DataBase => util/exporter}/output.py | 32 +++++++++---------- 10 files changed, 43 insertions(+), 47 deletions(-) create mode 100644 app/util/exporter/__init__.py rename app/{DataBase => util/exporter}/exporter.py (96%) rename app/{DataBase => util/exporter}/exporter_csv.py (88%) rename app/{DataBase => util/exporter}/exporter_docx.py (97%) rename app/{DataBase => util/exporter}/exporter_html.py (94%) rename app/{DataBase => util/exporter}/exporter_txt.py (97%) rename app/{DataBase => util/exporter}/output.py (93%) diff --git a/app/ui/contact/export/export_dialog.py b/app/ui/contact/export/export_dialog.py index 614db1a..3e440ea 100644 --- a/app/ui/contact/export/export_dialog.py +++ b/app/ui/contact/export/export_dialog.py @@ -4,15 +4,14 @@ import time from datetime import datetime, timedelta from PyQt5.QtCore import QTimer, QObject, pyqtSignal from PyQt5.QtGui import QTextCursor -from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QDialog, QVBoxLayout, QCheckBox, QHBoxLayout, \ - QProgressBar, QLabel, QMessageBox, QComboBox +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.ui.menu.export_time_range import TimeRangeDialog from .exportUi import Ui_Dialog -from app.DataBase.output import Output +from app.util.exporter.output import Output types = { '文本': 1, diff --git a/app/ui/mainview.py b/app/ui/mainview.py index eedb538..fa763d6 100644 --- a/app/ui/mainview.py +++ b/app/ui/mainview.py @@ -21,9 +21,8 @@ from . import mainwindow # 不能删,删了会出错 from .chat import ChatWindow from .contact import ContactWindow -from app.ui.tool.tool_window import ToolWindow from .menu.export import ExportDialog -from ..DataBase.output import Output +from app.util.exporter.output import Output from ..components.QCursorGif import QCursorGif from ..config import info_file_path, db_dir from ..log import logger diff --git a/app/ui/menu/export.py b/app/ui/menu/export.py index 809159c..9af91b3 100644 --- a/app/ui/menu/export.py +++ b/app/ui/menu/export.py @@ -1,5 +1,4 @@ import os -import sys import time from typing import List @@ -9,7 +8,7 @@ from PyQt5.QtGui import QTextCursor from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox from app.DataBase import micro_msg_db, misc_db -from app.DataBase.output import Output +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 diff --git a/app/util/exporter/__init__.py b/app/util/exporter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/DataBase/exporter.py b/app/util/exporter/exporter.py similarity index 96% rename from app/DataBase/exporter.py rename to app/util/exporter/exporter.py index fa0b4b4..5854452 100644 --- a/app/DataBase/exporter.py +++ b/app/util/exporter/exporter.py @@ -8,8 +8,8 @@ import filecmp from PyQt5.QtCore import pyqtSignal, QThread -from ..config import output_dir -from ..person import Me, Contact +from app.config import output_dir +from app.person import Me, Contact os.makedirs(os.path.join(output_dir, '聊天记录'), exist_ok=True) @@ -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.path.abspath('.'),output_dir,'聊天记录',self.contact.remark) + origin_path = os.path.join(os.getcwd(), output_dir, '聊天记录', self.contact.remark) makedirs(origin_path) def run(self): diff --git a/app/DataBase/exporter_csv.py b/app/util/exporter/exporter_csv.py similarity index 88% rename from app/DataBase/exporter_csv.py rename to app/util/exporter/exporter_csv.py index bcaa06e..94d2980 100644 --- a/app/DataBase/exporter_csv.py +++ b/app/util/exporter/exporter_csv.py @@ -2,14 +2,14 @@ import csv import os from app.DataBase import msg_db -from app.DataBase.exporter import ExporterBase +from app.util.exporter.exporter import ExporterBase 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.path.abspath('.'),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', diff --git a/app/DataBase/exporter_docx.py b/app/util/exporter/exporter_docx.py similarity index 97% rename from app/DataBase/exporter_docx.py rename to app/util/exporter/exporter_docx.py index 740cfdc..01f387e 100644 --- a/app/DataBase/exporter_docx.py +++ b/app/util/exporter/exporter_docx.py @@ -4,7 +4,6 @@ import time from re import findall import docx -import unicodedata from docx import shared from docx.enum.table import WD_ALIGN_VERTICAL from docx.enum.text import WD_COLOR_INDEX, WD_PARAGRAPH_ALIGNMENT @@ -12,7 +11,7 @@ from docx.oxml.ns import qn from docxcompose.composer import Composer from app.DataBase import msg_db, hard_link_db -from app.DataBase.exporter import ExporterBase, escape_js_and_html +from app.util.exporter.exporter import ExporterBase, escape_js_and_html from app.config import output_dir from app.log import logger from app.person import Me @@ -240,7 +239,7 @@ class DocxExporter(ExporterBase): return content_cell def music_share(self, doc, message): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) is_send = message[4] timestamp = message[5] content = music_share(message[11]) @@ -256,7 +255,7 @@ class DocxExporter(ExporterBase): display_name = self.get_display_name(is_send, message) def share_card(self, doc, message): - origin_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}" + origin_path = f"{os.path.abspath('../../DataBase')}/data/聊天记录/{self.contact.remark}" is_send = message[4] timestamp = message[5] bytesExtra = message[10] @@ -283,7 +282,7 @@ class DocxExporter(ExporterBase): app_logo = '' def merge_docx(self, conRemark, n): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录') + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录') all_file_path = [] for i in range(n): file_name = f"{conRemark}{i}.docx" @@ -306,7 +305,7 @@ class DocxExporter(ExporterBase): def export(self): print(f"【开始导出 DOCX {self.contact.remark}】") - origin_path = os.path.join(os.path.abspath('.'), 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: diff --git a/app/DataBase/exporter_html.py b/app/util/exporter/exporter_html.py similarity index 94% rename from app/DataBase/exporter_html.py rename to app/util/exporter/exporter_html.py index e230685..16f4e67 100644 --- a/app/DataBase/exporter_html.py +++ b/app/util/exporter/exporter_html.py @@ -7,7 +7,7 @@ from re import findall from PyQt5.QtCore import pyqtSignal, QThread from app.DataBase import msg_db, hard_link_db, media_msg_db -from app.DataBase.exporter import ExporterBase, escape_js_and_html +from app.util.exporter.exporter import ExporterBase, escape_js_and_html from app.config import output_dir from app.log import logger from app.person import Me @@ -63,7 +63,7 @@ class HtmlExporter(ExporterBase): ) def audio(self, doc, message): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) is_send = message[4] timestamp = message[5] bytesExtra = message[10] @@ -297,7 +297,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.path.abspath('.'), 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): @@ -379,7 +379,7 @@ class OutputMedia(QThread): self.contact = contact def run(self): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) messages = msg_db.get_messages_by_type(self.contact.wxid, 34) for message in messages: is_send = message[4] @@ -408,7 +408,7 @@ class OutputEmoji(QThread): self.contact = contact def run(self): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) messages = msg_db.get_messages_by_type(self.contact.wxid, 47) for message in messages: str_content = message[7] @@ -445,7 +445,7 @@ class OutputImage(QThread): print("图片导出完成") def run(self): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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') for message in messages: @@ -487,7 +487,7 @@ class OutputImageChild(QThread): self.messages = messages def run(self): - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录', self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) for message in self.messages: str_content = message[7] BytesExtra = message[10] diff --git a/app/DataBase/exporter_txt.py b/app/util/exporter/exporter_txt.py similarity index 97% rename from app/DataBase/exporter_txt.py rename to app/util/exporter/exporter_txt.py index 85b33fd..ccad4eb 100644 --- a/app/DataBase/exporter_txt.py +++ b/app/util/exporter/exporter_txt.py @@ -1,7 +1,7 @@ import os from app.DataBase import msg_db -from app.DataBase.exporter import ExporterBase +from app.util.exporter.exporter import ExporterBase 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.path.abspath('.'), 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) diff --git a/app/DataBase/output.py b/app/util/exporter/output.py similarity index 93% rename from app/DataBase/output.py rename to app/util/exporter/output.py index 1f60dc3..9f6d3c4 100644 --- a/app/DataBase/output.py +++ b/app/util/exporter/output.py @@ -5,22 +5,22 @@ import traceback from typing import List import docx -from PyQt5.QtCore import pyqtSignal, QThread, QObject +from PyQt5.QtCore import pyqtSignal, QThread from PyQt5.QtWidgets import QFileDialog from docx.oxml.ns import qn from docxcompose.composer import Composer -from app.DataBase.exporter_csv import CSVExporter -from app.DataBase.exporter_docx import DocxExporter -from app.DataBase.exporter_html import HtmlExporter -from app.DataBase.exporter_txt import TxtExporter +from app.util.exporter.exporter_csv import CSVExporter +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 .package_msg import PackageMsg -from ..DataBase import media_msg_db, hard_link_db, micro_msg_db, msg_db -from ..log import logger -from ..person import Me -from ..util.image import get_image +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) @@ -81,7 +81,7 @@ class Output(QThread): @return: """ - origin_path = os.path.join(os.path.abspath('.'), output_dir, '聊天记录') + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'), 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.path.abspath('.'),output_dir,'聊天记录',self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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.path.abspath('.'),output_dir,'聊天记录',self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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,7 +374,7 @@ class OutputImage(QThread): print('图片导出完成') def run(self): - origin_path = os.path.join(os.path.abspath('.'),output_dir,'聊天记录',self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), 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') for message in messages: @@ -406,7 +406,7 @@ class OutputImageChild(QThread): self.time_range = time_range def run(self): - origin_path = os.path.join(os.path.abspath('.'),output_dir,'聊天记录',self.contact.remark) + origin_path = os.path.join(os.path.abspath('../../DataBase'), output_dir, '聊天记录', self.contact.remark) for message in self.messages: str_content = message[7] BytesExtra = message[10]