修改路径

This commit is contained in:
SiYuan 2024-02-08 20:37:44 +08:00
parent c9c83fe5cc
commit ce2d1457d7
10 changed files with 43 additions and 47 deletions

View File

@ -4,15 +4,14 @@ import time
from datetime import datetime, timedelta from datetime import datetime, timedelta
from PyQt5.QtCore import QTimer, QObject, pyqtSignal from PyQt5.QtCore import QTimer, QObject, pyqtSignal
from PyQt5.QtGui import QTextCursor from PyQt5.QtGui import QTextCursor
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QDialog, QVBoxLayout, QCheckBox, QHBoxLayout, \ from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox
QProgressBar, QLabel, QMessageBox, QComboBox
from app.DataBase import msg_db from app.DataBase import msg_db
from app.components import ScrollBar 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 app.ui.menu.export_time_range import TimeRangeDialog
from .exportUi import Ui_Dialog from .exportUi import Ui_Dialog
from app.DataBase.output import Output from app.util.exporter.output import Output
types = { types = {
'文本': 1, '文本': 1,

View File

@ -21,9 +21,8 @@ from . import mainwindow
# 不能删,删了会出错 # 不能删,删了会出错
from .chat import ChatWindow from .chat import ChatWindow
from .contact import ContactWindow from .contact import ContactWindow
from app.ui.tool.tool_window import ToolWindow
from .menu.export import ExportDialog from .menu.export import ExportDialog
from ..DataBase.output import Output from app.util.exporter.output import Output
from ..components.QCursorGif import QCursorGif 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 ..log import logger

View File

@ -1,5 +1,4 @@
import os import os
import sys
import time import time
from typing import List from typing import List
@ -9,7 +8,7 @@ from PyQt5.QtGui import QTextCursor
from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox
from app.DataBase import micro_msg_db, misc_db 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 import ScrollBar
from app.components.export_contact_item import ContactQListWidgetItem from app.components.export_contact_item import ContactQListWidgetItem
from app.config import output_dir from app.config import output_dir

View File

View File

@ -8,8 +8,8 @@ import filecmp
from PyQt5.QtCore import pyqtSignal, QThread from PyQt5.QtCore import pyqtSignal, QThread
from ..config import output_dir from app.config import output_dir
from ..person import Me, Contact 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)
@ -104,7 +104,7 @@ class ExporterBase(QThread):
self.last_timestamp = 0 self.last_timestamp = 0
self.time_range = time_range self.time_range = time_range
self.messages = messages 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) makedirs(origin_path)
def run(self): def run(self):

View File

@ -2,14 +2,14 @@ import csv
import os import os
from app.DataBase import msg_db 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.config import output_dir
class CSVExporter(ExporterBase): class CSVExporter(ExporterBase):
def to_csv(self): def to_csv(self):
print(f"【开始导出 CSV {self.contact.remark}") 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) os.makedirs(origin_path, exist_ok=True)
filename = os.path.join(origin_path,f"{self.contact.remark}_utf8.csv") filename = os.path.join(origin_path,f"{self.contact.remark}_utf8.csv")
columns = ['localId', 'TalkerId', 'Type', 'SubType', columns = ['localId', 'TalkerId', 'Type', 'SubType',

View File

@ -4,7 +4,6 @@ import time
from re import findall from re import findall
import docx import docx
import unicodedata
from docx import shared from docx import shared
from docx.enum.table import WD_ALIGN_VERTICAL from docx.enum.table import WD_ALIGN_VERTICAL
from docx.enum.text import WD_COLOR_INDEX, WD_PARAGRAPH_ALIGNMENT 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 docxcompose.composer import Composer
from app.DataBase import msg_db, hard_link_db 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.config import output_dir
from app.log import logger from app.log import logger
from app.person import Me from app.person import Me
@ -240,7 +239,7 @@ class DocxExporter(ExporterBase):
return content_cell return content_cell
def music_share(self, doc, message): 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] is_send = message[4]
timestamp = message[5] timestamp = message[5]
content = music_share(message[11]) content = music_share(message[11])
@ -256,7 +255,7 @@ class DocxExporter(ExporterBase):
display_name = self.get_display_name(is_send, message) display_name = self.get_display_name(is_send, message)
def share_card(self, doc, 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] is_send = message[4]
timestamp = message[5] timestamp = message[5]
bytesExtra = message[10] bytesExtra = message[10]
@ -283,7 +282,7 @@ class DocxExporter(ExporterBase):
app_logo = '' app_logo = ''
def merge_docx(self, conRemark, n): 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 = [] all_file_path = []
for i in range(n): for i in range(n):
file_name = f"{conRemark}{i}.docx" file_name = f"{conRemark}{i}.docx"
@ -306,7 +305,7 @@ class DocxExporter(ExporterBase):
def export(self): def export(self):
print(f"【开始导出 DOCX {self.contact.remark}") 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) 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')) Me().save_avatar(os.path.join(origin_path, 'avatar', f'{Me().wxid}.png'))
if self.contact.is_chatroom: if self.contact.is_chatroom:

View File

@ -7,7 +7,7 @@ from re import findall
from PyQt5.QtCore import pyqtSignal, QThread from PyQt5.QtCore import pyqtSignal, QThread
from app.DataBase import msg_db, hard_link_db, media_msg_db 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.config import output_dir
from app.log import logger from app.log import logger
from app.person import Me from app.person import Me
@ -63,7 +63,7 @@ class HtmlExporter(ExporterBase):
) )
def audio(self, doc, message): 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_content = message[7]
str_time = message[8] str_time = message[8]
is_send = message[4] is_send = message[4]
@ -99,7 +99,7 @@ class HtmlExporter(ExporterBase):
) )
def file(self, doc, message): 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] bytesExtra = message[10]
compress_content = message[11] compress_content = message[11]
str_time = message[8] str_time = message[8]
@ -170,7 +170,7 @@ class HtmlExporter(ExporterBase):
) )
def video(self, doc, message): 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] type_ = message[2]
str_content = message[7] str_content = message[7]
str_time = message[8] str_time = message[8]
@ -211,7 +211,7 @@ class HtmlExporter(ExporterBase):
) )
def music_share(self, doc, message): 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] is_send = message[4]
timestamp = message[5] timestamp = message[5]
content = music_share(message[11]) content = music_share(message[11])
@ -232,7 +232,7 @@ class HtmlExporter(ExporterBase):
) )
def share_card(self, doc, message): 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] is_send = message[4]
timestamp = message[5] timestamp = message[5]
bytesExtra = message[10] bytesExtra = message[10]
@ -297,7 +297,7 @@ class HtmlExporter(ExporterBase):
def export(self): def export(self):
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 = 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') f'{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):
@ -379,7 +379,7 @@ class OutputMedia(QThread):
self.contact = contact self.contact = contact
def run(self): 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) messages = msg_db.get_messages_by_type(self.contact.wxid, 34)
for message in messages: for message in messages:
is_send = message[4] is_send = message[4]
@ -408,7 +408,7 @@ class OutputEmoji(QThread):
self.contact = contact self.contact = contact
def run(self): 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) messages = msg_db.get_messages_by_type(self.contact.wxid, 47)
for message in messages: for message in messages:
str_content = message[7] str_content = message[7]
@ -445,7 +445,7 @@ class OutputImage(QThread):
print("图片导出完成") print("图片导出完成")
def run(self): 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) 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: for message in messages:
@ -487,7 +487,7 @@ class OutputImageChild(QThread):
self.messages = messages self.messages = messages
def run(self): 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: for message in self.messages:
str_content = message[7] str_content = message[7]
BytesExtra = message[10] BytesExtra = message[10]

View File

@ -1,7 +1,7 @@
import os import os
from app.DataBase import msg_db 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.config import output_dir
from app.util.compress_content import parser_reply, share_card from app.util.compress_content import parser_reply, share_card
@ -112,7 +112,7 @@ class TxtExporter(ExporterBase):
def export(self): def export(self):
# 实现导出为txt的逻辑 # 实现导出为txt的逻辑
print(f"【开始导出 TXT {self.contact.remark}") 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) os.makedirs(origin_path, exist_ok=True)
filename = os.path.join(origin_path, self.contact.remark+'.txt') filename = os.path.join(origin_path, self.contact.remark+'.txt')
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)

View File

@ -5,22 +5,22 @@ import traceback
from typing import List from typing import List
import docx import docx
from PyQt5.QtCore import pyqtSignal, QThread, QObject from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5.QtWidgets import QFileDialog from PyQt5.QtWidgets import QFileDialog
from docx.oxml.ns import qn from docx.oxml.ns import qn
from docxcompose.composer import Composer from docxcompose.composer import Composer
from app.DataBase.exporter_csv import CSVExporter from app.util.exporter.exporter_csv import CSVExporter
from app.DataBase.exporter_docx import DocxExporter from app.util.exporter.exporter_docx import DocxExporter
from app.DataBase.exporter_html import HtmlExporter from app.util.exporter.exporter_html import HtmlExporter
from app.DataBase.exporter_txt import TxtExporter from app.util.exporter.exporter_txt import TxtExporter
from app.DataBase.hard_link import decodeExtraBuf from app.DataBase.hard_link import decodeExtraBuf
from app.config import output_dir from app.config import output_dir
from .package_msg import PackageMsg from app.DataBase.package_msg import PackageMsg
from ..DataBase import media_msg_db, hard_link_db, micro_msg_db, msg_db from app.DataBase import media_msg_db, hard_link_db, micro_msg_db, msg_db
from ..log import logger from app.log import logger
from ..person import Me from app.person import Me
from ..util.image import get_image 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)
@ -81,7 +81,7 @@ class Output(QThread):
@return: @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) os.makedirs(origin_path, exist_ok=True)
filename = QFileDialog.getSaveFileName(None, "save file", os.path.join(os.getcwd(), 'messages.csv'), filename = QFileDialog.getSaveFileName(None, "save file", os.path.join(os.getcwd(), 'messages.csv'),
"csv files (*.csv);;all files(*.*)") "csv files (*.csv);;all files(*.*)")
@ -169,7 +169,7 @@ class Output(QThread):
def merge_docx(self, n): def merge_docx(self, n):
conRemark = self.contact.remark 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" filename = f"{origin_path}/{conRemark}_{n}.docx"
if n == 10086: if n == 10086:
# self.document.append(self.document) # self.document.append(self.document)
@ -310,7 +310,7 @@ class OutputMedia(QThread):
self.time_range = time_range self.time_range = time_range
def run(self): 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) messages = msg_db.get_messages_by_type(self.contact.wxid, 34, time_range=self.time_range)
for message in messages: for message in messages:
is_send = message[4] is_send = message[4]
@ -337,7 +337,7 @@ class OutputEmoji(QThread):
self.time_range = time_range self.time_range = time_range
def run(self): 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) messages = msg_db.get_messages_by_type(self.contact.wxid, 47, time_range=self.time_range)
for message in messages: for message in messages:
str_content = message[7] str_content = message[7]
@ -374,7 +374,7 @@ class OutputImage(QThread):
print('图片导出完成') print('图片导出完成')
def run(self): 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) 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: for message in messages:
@ -406,7 +406,7 @@ class OutputImageChild(QThread):
self.time_range = time_range self.time_range = time_range
def run(self): 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: for message in self.messages:
str_content = message[7] str_content = message[7]
BytesExtra = message[10] BytesExtra = message[10]