mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-22 10:52:18 +08:00
年度报告支持自定义时间范围
This commit is contained in:
parent
ce2d1457d7
commit
610cd4673b
@ -1,3 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QUrl, QThread
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QToolButton, QMessageBox
|
||||
@ -5,6 +7,8 @@ from PyQt5.QtWidgets import QWidget, QMenu, QAction, QToolButton, QMessageBox
|
||||
from app.ui.Icon import Icon
|
||||
from .contactInfoUi import Ui_Form
|
||||
from .userinfo import userinfo
|
||||
from ..menu.export_time_range import TimeRangeDialog
|
||||
from ...DataBase import msg_db
|
||||
from ...person import Contact, Me
|
||||
from app.ui.contact.export.export_dialog import ExportDialog
|
||||
|
||||
@ -19,6 +23,7 @@ class ContactInfo(QWidget, Ui_Form):
|
||||
# username = ''
|
||||
def __init__(self, contact, parent=None):
|
||||
super(ContactInfo, self).__init__(parent)
|
||||
self.time_range = None
|
||||
self.setupUi(self)
|
||||
self.contact: Contact = contact
|
||||
self.view_userinfo = userinfo.UserinfoController(self.contact)
|
||||
@ -53,9 +58,11 @@ class ContactInfo(QWidget, Ui_Form):
|
||||
self.toDocxAct.triggered.connect(self.output)
|
||||
self.toCSVAct.triggered.connect(self.output)
|
||||
self.toTxtAct.triggered.connect(self.output)
|
||||
def set_contact(self,contact:Contact):
|
||||
|
||||
def set_contact(self, contact: Contact):
|
||||
self.view_userinfo.set_contact(contact)
|
||||
self.contact = contact
|
||||
|
||||
def toolButton_show(self):
|
||||
self.toolButton_output.showMenu()
|
||||
|
||||
@ -67,15 +74,27 @@ class ContactInfo(QWidget, Ui_Form):
|
||||
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/charts"))
|
||||
|
||||
def annual_report(self):
|
||||
date_range = None
|
||||
chat_calendar = msg_db.get_messages_calendar(self.contact.wxid)
|
||||
if chat_calendar:
|
||||
start_time = datetime.strptime(chat_calendar[0], "%Y-%m-%d")
|
||||
end_time = datetime.strptime(chat_calendar[-1], "%Y-%m-%d")
|
||||
date_range = (start_time.date(), end_time.date())
|
||||
self.time_range_view = TimeRangeDialog(date_range=date_range, parent=self)
|
||||
self.time_range_view.date_range_signal.connect(self.set_time_range)
|
||||
self.time_range_view.show()
|
||||
if 'room' in self.contact.wxid:
|
||||
QMessageBox.warning(
|
||||
self, '警告',
|
||||
'暂不支持群组'
|
||||
)
|
||||
return
|
||||
|
||||
def set_time_range(self, time_range):
|
||||
self.time_range = time_range
|
||||
self.contact.save_avatar()
|
||||
Me().save_avatar()
|
||||
self.report_thread = ReportThread(self.contact)
|
||||
self.report_thread = ReportThread(self.contact, time_range)
|
||||
self.report_thread.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314")))
|
||||
self.report_thread.start()
|
||||
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/christmas"))
|
||||
@ -100,24 +119,27 @@ class ContactInfo(QWidget, Ui_Form):
|
||||
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
||||
elif self.sender() == self.toCSVAct:
|
||||
# self.outputThread = Output(self.contact, type_=Output.CSV)
|
||||
dialog = ExportDialog(self.contact,title='选择导出的消息类型', file_type='csv', parent=self)
|
||||
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='csv', parent=self)
|
||||
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
||||
elif self.sender() == self.toHtmlAct:
|
||||
dialog = ExportDialog(self.contact,title='选择导出的消息类型', file_type='html', parent=self)
|
||||
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='html', parent=self)
|
||||
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
||||
elif self.sender() == self.toTxtAct:
|
||||
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='txt', parent=self)
|
||||
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
||||
|
||||
|
||||
class ReportThread(QThread):
|
||||
okSignal = pyqtSignal(bool)
|
||||
|
||||
def __init__(self, contact):
|
||||
def __init__(self, contact, time_range=None):
|
||||
super().__init__()
|
||||
self.contact = contact
|
||||
self.time_range = time_range
|
||||
|
||||
def run(self):
|
||||
from app.web_ui import web
|
||||
web.contact = self.contact
|
||||
web.time_range = self.time_range
|
||||
web.run(port='21314')
|
||||
self.okSignal.emit(True)
|
||||
|
@ -28,12 +28,15 @@ types = {
|
||||
}
|
||||
Stylesheet = """
|
||||
"""
|
||||
|
||||
|
||||
class EmittingStr(QObject):
|
||||
textWritten = pyqtSignal(str) # 定义一个发送str的信号
|
||||
|
||||
def write(self, text):
|
||||
self.textWritten.emit(str(text))
|
||||
|
||||
|
||||
class ExportDialog(QDialog, Ui_Dialog):
|
||||
def __init__(self, contact=None, title="选择导出的类型", file_type="csv", parent=None):
|
||||
super(ExportDialog, self).__init__(parent)
|
||||
@ -50,7 +53,7 @@ class ExportDialog(QDialog, Ui_Dialog):
|
||||
self.export_type = Output.HTML
|
||||
self.export_choices = {"文本": True, "图片": True, "语音": False, "视频": False, "表情包": False,
|
||||
'音乐与音频': False, '分享卡片': False, '文件': False,
|
||||
'转账': False, '音视频通话': False,'拍一拍等系统消息': True} # 定义导出的数据类型,默认全部选择
|
||||
'转账': False, '音视频通话': False, '拍一拍等系统消息': True} # 定义导出的数据类型,默认全部选择
|
||||
elif file_type == 'csv':
|
||||
self.export_type = Output.CSV
|
||||
self.export_choices = {"文本": True, "图片": True, "视频": True, "表情包": True} # 定义导出的数据类型,默认全部选择
|
||||
@ -104,19 +107,20 @@ class ExportDialog(QDialog, Ui_Dialog):
|
||||
self.timer.start(1000)
|
||||
self.start_time = time.time()
|
||||
# self.accept() # 使用accept关闭对话框
|
||||
|
||||
def outputWritten(self, text):
|
||||
cursor = self.textBrowser.textCursor()
|
||||
cursor.movePosition(QTextCursor.End)
|
||||
cursor.insertText(text)
|
||||
self.textBrowser.setTextCursor(cursor)
|
||||
self.textBrowser.ensureCursorVisible()
|
||||
|
||||
def set_export_date(self):
|
||||
date_range = self.comboBox_time.currentText()
|
||||
if date_range == '全部时间':
|
||||
pass
|
||||
elif date_range == '最近三个月':
|
||||
|
||||
|
||||
# 获取今天的日期和时间
|
||||
today = datetime.now()
|
||||
|
||||
@ -142,8 +146,8 @@ class ExportDialog(QDialog, Ui_Dialog):
|
||||
if chat_calendar:
|
||||
start_time = datetime.strptime(chat_calendar[0], "%Y-%m-%d")
|
||||
end_time = datetime.strptime(chat_calendar[-1], "%Y-%m-%d")
|
||||
date_range = (start_time.date(),end_time.date())
|
||||
self.time_range_view = TimeRangeDialog(date_range=date_range,parent=self)
|
||||
date_range = (start_time.date(), end_time.date())
|
||||
self.time_range_view = TimeRangeDialog(date_range=date_range, parent=self)
|
||||
self.time_range_view.date_range_signal.connect(self.set_time_range)
|
||||
self.time_range_view.show()
|
||||
self.comboBox_time.setCurrentIndex(0)
|
||||
@ -169,7 +173,8 @@ 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_()
|
||||
@ -204,6 +209,7 @@ class ExportDialog(QDialog, Ui_Dialog):
|
||||
del self.worker
|
||||
super().close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
|
@ -15,7 +15,9 @@ app = Flask(__name__)
|
||||
|
||||
wxid = ''
|
||||
contact: Contact = None
|
||||
|
||||
start_time = '2023-1-01 00:00:00'
|
||||
end_time = '2023-12-31 23:59:59'
|
||||
time_range = (start_time, end_time)
|
||||
html: str = ''
|
||||
api_url = 'http://api.lc044.love/upload'
|
||||
|
||||
@ -28,13 +30,7 @@ def index():
|
||||
|
||||
@app.route("/christmas")
|
||||
def christmas():
|
||||
t = '2023-1-01 00:00:00'
|
||||
s_t = time.strptime(t, "%Y-%m-%d %H:%M:%S") # 返回元祖
|
||||
start_time = int(time.mktime(s_t))
|
||||
t = '2023-12-31 23:59:59'
|
||||
s_t = time.strptime(t, "%Y-%m-%d %H:%M:%S") # 返回元祖
|
||||
end_time = int(time.mktime(s_t))
|
||||
time_range = (start_time, end_time)
|
||||
|
||||
# 渲染模板,并传递图表的 HTML 到模板中
|
||||
try:
|
||||
first_message, first_time = msg_db.get_first_time_of_message(contact.wxid)
|
||||
@ -164,7 +160,10 @@ def test():
|
||||
|
||||
|
||||
def run(port=21314):
|
||||
try:
|
||||
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def resource_path(relative_path):
|
||||
|
Loading…
Reference in New Issue
Block a user