Skip to content

Commit

Permalink
导出所有数据库的聊天记录
Browse files Browse the repository at this point in the history
  • Loading branch information
LC044 committed Nov 16, 2023
1 parent 3808049 commit 9c7cb67
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 55 deletions.
74 changes: 34 additions & 40 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions app/DataBase/micro_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ def get_contact():
return result


def close():
global DB
if DB:
DB.close()


if __name__ == '__main__':
get_contact()
56 changes: 41 additions & 15 deletions app/DataBase/msg.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
import os.path
import re
import sqlite3

DB = None
cursor = None
msg_path = "./app/Database/Msg/MSG0.db"
DB = []
cursor = []
msg_root_path = "./app/Database/Msg/"
# misc_path = './Msg/Misc.db'
if os.path.exists(msg_path):
DB = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
if os.path.exists(msg_root_path):
for root, dirs, files in os.walk(msg_root_path):
for file in files:
if re.match('^MSG[0-9]+\.db$', file):
# print('ok', file)
msg_path = os.path.join(msg_root_path, file)
DB0 = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor0 = DB0.cursor()
DB.append(DB0)
cursor.append(cursor0)


def init_database():
global DB
global cursor
if not DB:
if os.path.exists(msg_path):
DB = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor = DB.cursor()
if os.path.exists(msg_root_path):
for root, dirs, files in os.walk(msg_root_path):
for file in files:
# print(file)
if re.match('^MSG[0-9]+\.db$', file):
print('ok', file)
msg_path = os.path.join(msg_root_path, file)
DB0 = sqlite3.connect(msg_path, check_same_thread=False)
# '''创建游标'''
cursor0 = DB0.cursor()
DB.append(DB0)
cursor.append(cursor0)


def get_messages(username_):
Expand All @@ -28,15 +44,25 @@ def get_messages(username_):
where StrTalker=?
order by CreateTime
'''
cursor.execute(sql, [username_])
result_ = cursor.fetchall()
return result_
result = []
for cur in cursor:
cur.execute(sql, [username_])
result_ = cur.fetchall()
# print(len(result))
result += result_
result.sort(key=lambda x: x[5])
return result


def close():
for db in DB:
db.close()


if __name__ == '__main__':
from pprint import pprint

msg_path = './Msg/MSG3.db'
msg_root_path = './Msg/'
init_database()

username = 'wxid_0o18ef858vnu22'
Expand Down
7 changes: 7 additions & 0 deletions app/ui_pc/mainview.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from PyQt5.QtWidgets import *

from app import config
from app.DataBase import msg
from app.Ui.Icon import Icon
from . import mainwindow
from .contact import ContactWindow
Expand Down Expand Up @@ -112,3 +113,9 @@ def about(self):
f"QQ交流群:{config.contact}\n"
"地址:https://github.com/LC044/WeChatMsg"
)

def close(self) -> bool:
del self.listWidget
del self.stackedWidget
msg.close()
self.contact_window.close()

0 comments on commit 9c7cb67

Please sign in to comment.