mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-23 03:22:17 +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.QtCore import pyqtSignal, QUrl, QThread
|
||||||
from PyQt5.QtGui import QDesktopServices
|
from PyQt5.QtGui import QDesktopServices
|
||||||
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QToolButton, QMessageBox
|
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 app.ui.Icon import Icon
|
||||||
from .contactInfoUi import Ui_Form
|
from .contactInfoUi import Ui_Form
|
||||||
from .userinfo import userinfo
|
from .userinfo import userinfo
|
||||||
|
from ..menu.export_time_range import TimeRangeDialog
|
||||||
|
from ...DataBase import msg_db
|
||||||
from ...person import Contact, Me
|
from ...person import Contact, Me
|
||||||
from app.ui.contact.export.export_dialog import ExportDialog
|
from app.ui.contact.export.export_dialog import ExportDialog
|
||||||
|
|
||||||
@ -19,6 +23,7 @@ class ContactInfo(QWidget, Ui_Form):
|
|||||||
# username = ''
|
# username = ''
|
||||||
def __init__(self, contact, parent=None):
|
def __init__(self, contact, parent=None):
|
||||||
super(ContactInfo, self).__init__(parent)
|
super(ContactInfo, self).__init__(parent)
|
||||||
|
self.time_range = None
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self.contact: Contact = contact
|
self.contact: Contact = contact
|
||||||
self.view_userinfo = userinfo.UserinfoController(self.contact)
|
self.view_userinfo = userinfo.UserinfoController(self.contact)
|
||||||
@ -53,9 +58,11 @@ class ContactInfo(QWidget, Ui_Form):
|
|||||||
self.toDocxAct.triggered.connect(self.output)
|
self.toDocxAct.triggered.connect(self.output)
|
||||||
self.toCSVAct.triggered.connect(self.output)
|
self.toCSVAct.triggered.connect(self.output)
|
||||||
self.toTxtAct.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.view_userinfo.set_contact(contact)
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
|
|
||||||
def toolButton_show(self):
|
def toolButton_show(self):
|
||||||
self.toolButton_output.showMenu()
|
self.toolButton_output.showMenu()
|
||||||
|
|
||||||
@ -67,15 +74,27 @@ class ContactInfo(QWidget, Ui_Form):
|
|||||||
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/charts"))
|
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/charts"))
|
||||||
|
|
||||||
def annual_report(self):
|
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:
|
if 'room' in self.contact.wxid:
|
||||||
QMessageBox.warning(
|
QMessageBox.warning(
|
||||||
self, '警告',
|
self, '警告',
|
||||||
'暂不支持群组'
|
'暂不支持群组'
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def set_time_range(self, time_range):
|
||||||
|
self.time_range = time_range
|
||||||
self.contact.save_avatar()
|
self.contact.save_avatar()
|
||||||
Me().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.okSignal.connect(lambda x: QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314")))
|
||||||
self.report_thread.start()
|
self.report_thread.start()
|
||||||
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/christmas"))
|
QDesktopServices.openUrl(QUrl("http://127.0.0.1:21314/christmas"))
|
||||||
@ -109,15 +128,18 @@ class ContactInfo(QWidget, Ui_Form):
|
|||||||
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='txt', parent=self)
|
dialog = ExportDialog(self.contact, title='选择导出的消息类型', file_type='txt', parent=self)
|
||||||
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
result = dialog.exec_() # 使用exec_()获取用户的操作结果
|
||||||
|
|
||||||
|
|
||||||
class ReportThread(QThread):
|
class ReportThread(QThread):
|
||||||
okSignal = pyqtSignal(bool)
|
okSignal = pyqtSignal(bool)
|
||||||
|
|
||||||
def __init__(self, contact):
|
def __init__(self, contact, time_range=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.contact = contact
|
self.contact = contact
|
||||||
|
self.time_range = time_range
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
from app.web_ui import web
|
from app.web_ui import web
|
||||||
web.contact = self.contact
|
web.contact = self.contact
|
||||||
|
web.time_range = self.time_range
|
||||||
web.run(port='21314')
|
web.run(port='21314')
|
||||||
self.okSignal.emit(True)
|
self.okSignal.emit(True)
|
||||||
|
@ -28,12 +28,15 @@ types = {
|
|||||||
}
|
}
|
||||||
Stylesheet = """
|
Stylesheet = """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class EmittingStr(QObject):
|
class EmittingStr(QObject):
|
||||||
textWritten = pyqtSignal(str) # 定义一个发送str的信号
|
textWritten = pyqtSignal(str) # 定义一个发送str的信号
|
||||||
|
|
||||||
def write(self, text):
|
def write(self, text):
|
||||||
self.textWritten.emit(str(text))
|
self.textWritten.emit(str(text))
|
||||||
|
|
||||||
|
|
||||||
class ExportDialog(QDialog, Ui_Dialog):
|
class ExportDialog(QDialog, Ui_Dialog):
|
||||||
def __init__(self, contact=None, title="选择导出的类型", file_type="csv", parent=None):
|
def __init__(self, contact=None, title="选择导出的类型", file_type="csv", parent=None):
|
||||||
super(ExportDialog, self).__init__(parent)
|
super(ExportDialog, self).__init__(parent)
|
||||||
@ -104,19 +107,20 @@ class ExportDialog(QDialog, Ui_Dialog):
|
|||||||
self.timer.start(1000)
|
self.timer.start(1000)
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
# self.accept() # 使用accept关闭对话框
|
# self.accept() # 使用accept关闭对话框
|
||||||
|
|
||||||
def outputWritten(self, text):
|
def outputWritten(self, text):
|
||||||
cursor = self.textBrowser.textCursor()
|
cursor = self.textBrowser.textCursor()
|
||||||
cursor.movePosition(QTextCursor.End)
|
cursor.movePosition(QTextCursor.End)
|
||||||
cursor.insertText(text)
|
cursor.insertText(text)
|
||||||
self.textBrowser.setTextCursor(cursor)
|
self.textBrowser.setTextCursor(cursor)
|
||||||
self.textBrowser.ensureCursorVisible()
|
self.textBrowser.ensureCursorVisible()
|
||||||
|
|
||||||
def set_export_date(self):
|
def set_export_date(self):
|
||||||
date_range = self.comboBox_time.currentText()
|
date_range = self.comboBox_time.currentText()
|
||||||
if date_range == '全部时间':
|
if date_range == '全部时间':
|
||||||
pass
|
pass
|
||||||
elif date_range == '最近三个月':
|
elif date_range == '最近三个月':
|
||||||
|
|
||||||
|
|
||||||
# 获取今天的日期和时间
|
# 获取今天的日期和时间
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
|
|
||||||
@ -169,7 +173,8 @@ class ExportDialog(QDialog, Ui_Dialog):
|
|||||||
reply = QMessageBox(self)
|
reply = QMessageBox(self)
|
||||||
reply.setIcon(QMessageBox.Information)
|
reply.setIcon(QMessageBox.Information)
|
||||||
reply.setWindowTitle('OK')
|
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.AcceptRole)
|
||||||
reply.addButton("取消", QMessageBox.RejectRole)
|
reply.addButton("取消", QMessageBox.RejectRole)
|
||||||
api = reply.exec_()
|
api = reply.exec_()
|
||||||
@ -204,6 +209,7 @@ class ExportDialog(QDialog, Ui_Dialog):
|
|||||||
del self.worker
|
del self.worker
|
||||||
super().close()
|
super().close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -15,7 +15,9 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
wxid = ''
|
wxid = ''
|
||||||
contact: Contact = None
|
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 = ''
|
html: str = ''
|
||||||
api_url = 'http://api.lc044.love/upload'
|
api_url = 'http://api.lc044.love/upload'
|
||||||
|
|
||||||
@ -28,13 +30,7 @@ def index():
|
|||||||
|
|
||||||
@app.route("/christmas")
|
@app.route("/christmas")
|
||||||
def 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 到模板中
|
# 渲染模板,并传递图表的 HTML 到模板中
|
||||||
try:
|
try:
|
||||||
first_message, first_time = msg_db.get_first_time_of_message(contact.wxid)
|
first_message, first_time = msg_db.get_first_time_of_message(contact.wxid)
|
||||||
@ -164,7 +160,10 @@ def test():
|
|||||||
|
|
||||||
|
|
||||||
def run(port=21314):
|
def run(port=21314):
|
||||||
|
try:
|
||||||
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)
|
app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def resource_path(relative_path):
|
def resource_path(relative_path):
|
||||||
|
Loading…
Reference in New Issue
Block a user