Skip to content

Commit

Permalink
支持单个联系人选择导出日期
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Jan 10, 2024
1 parent 88770e0 commit e7de20d
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 112 deletions.
56 changes: 25 additions & 31 deletions app/DataBase/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_message_by_num(self, username_, local_id):
# result.sort(key=lambda x: x[5])
return parser_chatroom_message(result) if username_.__contains__('@chatroom') else result

def get_messages_by_type(self, username_, type_, year_='all',time_range=None):
def get_messages_by_type(self, username_, type_, year_='all', time_range=None):
if not self.open_flag:
return None
if time_range:
Expand Down Expand Up @@ -344,6 +344,28 @@ def get_contact(self, contacts):
contacts.sort(key=lambda cur_contact: cur_contact[-1], reverse=True)
return contacts

def get_messages_calendar(self, username_):
sql = '''
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days
from (
SELECT MsgSvrID, CreateTime
FROM MSG
WHERE StrTalker = ?
ORDER BY CreateTime
)
group by days
'''
if not self.open_flag:
print('数据库未就绪')
return None
try:
lock.acquire(True)
self.cursor.execute(sql, [username_])
result = self.cursor.fetchall()
finally:
lock.release()
return [date[0] for date in result]

def get_messages_by_days(self, username_, is_Annual_report_=False, year_='2023'):
if is_Annual_report_:
sql = '''
Expand Down Expand Up @@ -694,39 +716,11 @@ def __del__(self):


if __name__ == '__main__':
db_path = "./app/database/Msg/MSG.db"
db_path = "./Msg/MSG.db"
msg = Msg()
msg.init_database()
wxid = 'wxid_0o18ef858vnu22'
wxid = '24521163022@chatroom'
wxid = 'wxid_vtz9jk9ulzjt22' # si
print()
from app.util import compress_content
import xml.etree.ElementTree as ET

msgs = msg.get_messages(wxid)

for msg in msgs:
if msg[2] == 49 and msg[3] == 5:
xml = compress_content.decompress_CompressContent(msg[11])
root = ET.XML(xml)
appmsg = root.find('appmsg')
title = appmsg.find('title').text
des = appmsg.find('des').text
url = appmsg.find('url').text
appinfo = root.find('appinfo')
show_display_name = appmsg.find('sourcedisplayname')
if show_display_name is not None:
show_display_name = show_display_name.text
else:
show_display_name = appinfo.find('appname').text
print(title, des, url, show_display_name)
msg_bytes = MessageBytesExtra()
msg_bytes.ParseFromString(msg[10])
for tmp in msg_bytes.message2:
if tmp.field1 == 3:
thumb = tmp.field2
print(thumb)
if tmp.field2 == 4:
app_logo = tmp.field2
print('logo', app_logo)
print(msg.get_messages_calendar(wxid))
39 changes: 34 additions & 5 deletions app/components/calendar_dialog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import time

from PyQt5 import QtWidgets
from PyQt5.QtCore import QTimer, QThread, pyqtSignal
from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox, QCalendarWidget, QWidget, QVBoxLayout
from datetime import datetime, timedelta
from PyQt5.QtCore import QTimer, QThread, pyqtSignal, Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QDialog, QCheckBox, QMessageBox, QCalendarWidget, QWidget, QVBoxLayout, \
QToolButton

from app.ui.Icon import Icon


class CalendarDialog(QDialog):
Expand All @@ -18,12 +22,37 @@ def __init__(self, date_range=None, parent=None):
self.setWindowTitle('选择日期')
self.calendar = QCalendarWidget(self)
self.calendar.clicked.connect(self.onDateChanged)
prev_btn = self.calendar.findChild(QToolButton, "qt_calendar_prevmonth")
prev_btn.setIcon(Icon.Arrow_left_Icon)
next_btn = self.calendar.findChild(QToolButton, "qt_calendar_nextmonth")
next_btn.setIcon(Icon.Arrow_right_Icon)
self.date_range = date_range
if date_range:
self.calendar.setDateRange(*date_range)
# 从第一天开始,依次添加日期到列表,直到该月的最后一天
current_date = date_range[1]
while (current_date + timedelta(days=1)).month == date_range[1].month:
current_date += timedelta(days=1)
range_format = self.calendar.dateTextFormat(current_date)
range_format.setForeground(Qt.gray)
self.calendar.setDateTextFormat(current_date, range_format)
# 从第一天开始,依次添加日期到列表,直到该月的最后一天
current_date = date_range[0]
while (current_date - timedelta(days=1)).month == date_range[0].month:
current_date -= timedelta(days=1)
range_format = self.calendar.dateTextFormat(current_date)
range_format.setForeground(Qt.gray)
self.calendar.setDateTextFormat(current_date, range_format)
layout = QVBoxLayout(self)
layout.addWidget(self.calendar)
self.setLayout(layout)

def set_start_date(self):
if self.date_range:
self.calendar.setCurrentPage(self.date_range[0].year, self.date_range[0].month)
def set_end_date(self):
if self.date_range:
self.calendar.setCurrentPage(self.date_range[1].year, self.date_range[1].month)
def onDateChanged(self):
# 获取选择的日期
selected_date = self.calendar.selectedDate()
Expand All @@ -37,11 +66,11 @@ def onDateChanged(self):

if __name__ == '__main__':
import sys
from datetime import datetime
from datetime import datetime, timedelta

app = QApplication(sys.argv)
# 设置日期范围
start_date = datetime(2023, 12, 11)
start_date = datetime(2024, 1, 5)
end_date = datetime(2024, 1, 9)
date_range = (start_date.date(), end_date.date())
ex = CalendarDialog(date_range=date_range)
Expand Down
1 change: 1 addition & 0 deletions app/resources/icons/arrow-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/resources/icons/arrow-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/resources/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<file>icons/woman.svg</file>
<file>icons/select.svg</file>
<file>icons/unselect.svg</file>
<file>icons/arrow-left.svg</file>
<file>icons/arrow-right.svg</file>
</qresource>
</RCC>
Loading

0 comments on commit e7de20d

Please sign in to comment.