forked from LC044/WeChatMsg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request LC044#12 from LC044/dev_zsk
Dev zsk
- Loading branch information
Showing
49 changed files
with
3,255 additions
and
461 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os.path | ||
import sqlite3 | ||
|
||
DB = None | ||
cursor = None | ||
misc_path = "./app/Database/Msg/Misc.db" | ||
# misc_path = './Msg/Misc.db' | ||
if os.path.exists(misc_path): | ||
DB = sqlite3.connect(misc_path, check_same_thread=False) | ||
# '''创建游标''' | ||
cursor = DB.cursor() | ||
|
||
|
||
def get_avatar_buffer(userName): | ||
sql = ''' | ||
select smallHeadBuf | ||
from ContactHeadImg1 | ||
where usrName=?; | ||
''' | ||
cursor.execute(sql, [userName]) | ||
result = cursor.fetchall() | ||
# print(result[0][0]) | ||
if result: | ||
return result[0][0] | ||
return None | ||
|
||
|
||
if __name__ == '__main__': | ||
get_avatar_buffer('wxid_al2oan01b6fn11') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os.path | ||
import re | ||
import sqlite3 | ||
|
||
DB = [] | ||
cursor = [] | ||
msg_root_path = "./app/Database/Msg/" | ||
# misc_path = './Msg/Misc.db' | ||
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_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_): | ||
sql = ''' | ||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime | ||
from MSG | ||
where StrTalker=? | ||
order by CreateTime | ||
''' | ||
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_root_path = './Msg/' | ||
init_database() | ||
|
||
username = 'wxid_0o18ef858vnu22' | ||
result = get_messages(username) | ||
pprint(result) | ||
pprint(len(result)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
|
||
import pandas as pd | ||
from PyQt5.QtCore import pyqtSignal, QThread | ||
|
||
from . import msg | ||
from ..log import log | ||
|
||
|
||
class Output(QThread): | ||
""" | ||
发送信息线程 | ||
""" | ||
progressSignal = pyqtSignal(int) | ||
rangeSignal = pyqtSignal(int) | ||
okSignal = pyqtSignal(int) | ||
i = 1 | ||
CSV = 0 | ||
DOCX = 1 | ||
HTML = 2 | ||
|
||
def __init__(self, contact, parent=None, type_=DOCX): | ||
super().__init__(parent) | ||
self.sec = 2 # 默认1000秒 | ||
self.contact = contact | ||
self.ta_username = contact.wxid | ||
self.msg_id = 0 | ||
self.output_type = type_ | ||
self.total_num = 0 | ||
self.num = 0 | ||
|
||
@log | ||
def to_csv(self, conRemark, path): | ||
origin_docx_path = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}" | ||
if not os.path.exists(origin_docx_path): | ||
os.mkdir(origin_docx_path) | ||
filename = f"{os.path.abspath('.')}/data/聊天记录/{self.contact.remark}/{self.contact.remark}.csv" | ||
# columns = ["用户名", "消息内容", "发送时间", "发送状态", "消息类型", "isSend", "msgId"] | ||
columns = ['localId', 'TalkerId', 'Type', 'SubType', | ||
'IsSender', 'CreateTime', 'Status', 'StrContent', | ||
'StrTime'] | ||
messages = msg.get_messages(self.contact.wxid) | ||
# print() | ||
df = pd.DataFrame( | ||
data=messages, | ||
columns=columns, | ||
) | ||
df.to_csv(filename, encoding='utf-8') | ||
self.okSignal.emit('ok') | ||
|
||
def run(self): | ||
if self.output_type == self.DOCX: | ||
return | ||
elif self.output_type == self.CSV: | ||
# print("线程导出csv") | ||
self.to_csv(self.ta_username, "path") |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.