From 3a5bd4d5d5823bfb60ccdc7d9284886718edd292 Mon Sep 17 00:00:00 2001 From: shuaikangzhou <863909694@qq.com> Date: Mon, 23 Jan 2023 09:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BAword=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/data.py | 60 ++++++++++++++++++++++++++++++++++++----- app/DataBase/to_docx.py | 33 +++++++++++------------ app/Ui/chat/chat.py | 26 ++++++------------ app/Ui/mainview.py | 2 +- 4 files changed, 77 insertions(+), 44 deletions(-) diff --git a/app/DataBase/data.py b/app/DataBase/data.py index f2d8ae1..db161b2 100644 --- a/app/DataBase/data.py +++ b/app/DataBase/data.py @@ -121,11 +121,14 @@ def get_conRemark(username): else: return result[1] + def get_nickname(username): sql = 'select nickname,alias from rcontact where username=?' cursor.execute(sql, [username]) result = cursor.fetchone() return result + + def avatar_md5(wxid): m = hashlib.md5() # 参数必须是byte类型,否则报Unicode-objects must be encoded before hashing错误 @@ -160,6 +163,43 @@ def get_message(wxid, num): return cursor.fetchall() +def search_send_message(start_time, end_time): + start_time = '2022-1-1 00:00:00' + end_time = '2023-1-1 00:00:00' + start = time.mktime(time.strptime(start_time, '%Y-%m-%d %H:%M:%S')) + end = time.mktime(time.strptime(end_time, '%Y-%m-%d %H:%M:%S')) + sql = ''' + select count(*) from message + where createTime >? and createTime < ? and isSend=0 and talker like '%wxid%'; + ''' + cursor.execute(sql,[start*1000 , end*1000]) + return cursor.fetchone() + + +def clearImagePath(imgpath): + path = imgpath.split('/') + newPath = '/'.join(path[:-1]) + '/' + path[-1][3:] + '.jpg' + if os.path.exists(newPath): + return newPath + newPath = '/'.join(path[:-1]) + '/' + path[-1][3:] + '.png' + if os.path.exists(newPath): + return newPath + newPath = '/'.join(path[:-1]) + '/' + path[-1] + 'hd' + if os.path.exists(newPath): + return newPath + return imgpath + + +def get_all_message(wxid): + sql = ''' + select * from message + where talker = ? + order by msgId + ''' + cursor.execute(sql, [wxid]) + return cursor.fetchall() + + def get_emoji(imgPath): newPath = f"{os.path.abspath('.')}/app/data/emoji/{imgPath}" if os.path.exists(newPath): @@ -172,7 +212,7 @@ def get_emoji(imgPath): ''' cursor.execute(sql, [imgPath]) result = cursor.fetchone() - download_emoji(newPath,result[0]) + download_emoji(newPath, result[0]) return newPath @@ -182,9 +222,10 @@ def download_emoji(imgPath, url): f.write(resp.content) return imgPath -def get_chatroom_displayname(chatroom,username): + +def get_chatroom_displayname(chatroom, username): sql = 'select memberlist,displayname from chatroom where chatroomname =?' - cursor.execute(sql,[chatroom]) + cursor.execute(sql, [chatroom]) result = cursor.fetchone() wxids = result[0].split(';') names = result[1].split('、') @@ -194,6 +235,8 @@ def get_chatroom_displayname(chatroom,username): for i in wxids: print(get_conRemark(i)) return names[id] + + def get_contacts(): sql = ''' select * from rcontact @@ -202,11 +245,14 @@ def get_contacts(): cursor.execute(sql) result = cursor.fetchall() return result + + if __name__ == '__main__': # rconversation = get_rconversation() # for i in rconversation: # print(i) - contacts = get_contacts() - for contact in contacts: - print(contact) - + # contacts = get_all_message('wxid_vqave8lcp49r22') + # for contact in contacts: + # print(contact) + # [(177325,)] (73546,) (103770,) + print(search_send_message(1,1)) diff --git a/app/DataBase/to_docx.py b/app/DataBase/to_docx.py index 087b2fc..b282b59 100644 --- a/app/DataBase/to_docx.py +++ b/app/DataBase/to_docx.py @@ -37,7 +37,7 @@ def mkdir(path): return True -mkdir(path+'/emoji') +mkdir(path + '/emoji') # mkdir('..//db_tables') ''' #! 将wxid使用MD5编码加密 @@ -68,6 +68,7 @@ def get_avator(wxid): break return Path + '/' + avatar + def read_csv(conRemark): ''' :param conRemark: (str) 要导出的联系人备注名 @@ -118,9 +119,6 @@ def time_format(timestamp): return time.strftime("%Y-%m-%d %H:%M:%S", time_tuple) - - - def IS_5_min(last_m, now_m): ''' #! 判断两次聊天时间是不是大于五分钟 @@ -140,11 +138,6 @@ def judge_type(Type): pass - - - - - '''合并word文档到一个文件里''' @@ -176,6 +169,7 @@ class MyThread(QThread): self_text = pyqtSignal(str) ta_text = pyqtSignal(str) bar = pyqtSignal(int) + def __init__(self): super(MyThread, self).__init__() self.ta_info = {} @@ -206,7 +200,8 @@ class MyThread(QThread): # print(user_data) self.total_num = len(user_data) return user_data - def create_table(self,doc, isSend): + + def create_table(self, doc, isSend): ''' #! 创建一个1*2表格 #! isSend = 1 (0,0)存聊天内容,(0,1)存头像 @@ -301,7 +296,7 @@ class MyThread(QThread): :return: ''' if 1: - # try: + # try: Path = f'{path}/emoji/{imgPath}' is_Exist = os.path.exists(Path) if not is_Exist: @@ -324,7 +319,7 @@ class MyThread(QThread): filename = r.lstrip('