mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-22 10:52:18 +08:00
导出word文档
This commit is contained in:
parent
f5989290f9
commit
3a5bd4d5d5
@ -121,11 +121,14 @@ def get_conRemark(username):
|
|||||||
else:
|
else:
|
||||||
return result[1]
|
return result[1]
|
||||||
|
|
||||||
|
|
||||||
def get_nickname(username):
|
def get_nickname(username):
|
||||||
sql = 'select nickname,alias from rcontact where username=?'
|
sql = 'select nickname,alias from rcontact where username=?'
|
||||||
cursor.execute(sql, [username])
|
cursor.execute(sql, [username])
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def avatar_md5(wxid):
|
def avatar_md5(wxid):
|
||||||
m = hashlib.md5()
|
m = hashlib.md5()
|
||||||
# 参数必须是byte类型,否则报Unicode-objects must be encoded before hashing错误
|
# 参数必须是byte类型,否则报Unicode-objects must be encoded before hashing错误
|
||||||
@ -160,6 +163,43 @@ def get_message(wxid, num):
|
|||||||
return cursor.fetchall()
|
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):
|
def get_emoji(imgPath):
|
||||||
newPath = f"{os.path.abspath('.')}/app/data/emoji/{imgPath}"
|
newPath = f"{os.path.abspath('.')}/app/data/emoji/{imgPath}"
|
||||||
if os.path.exists(newPath):
|
if os.path.exists(newPath):
|
||||||
@ -172,7 +212,7 @@ def get_emoji(imgPath):
|
|||||||
'''
|
'''
|
||||||
cursor.execute(sql, [imgPath])
|
cursor.execute(sql, [imgPath])
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
download_emoji(newPath,result[0])
|
download_emoji(newPath, result[0])
|
||||||
return newPath
|
return newPath
|
||||||
|
|
||||||
|
|
||||||
@ -182,9 +222,10 @@ def download_emoji(imgPath, url):
|
|||||||
f.write(resp.content)
|
f.write(resp.content)
|
||||||
return imgPath
|
return imgPath
|
||||||
|
|
||||||
def get_chatroom_displayname(chatroom,username):
|
|
||||||
|
def get_chatroom_displayname(chatroom, username):
|
||||||
sql = 'select memberlist,displayname from chatroom where chatroomname =?'
|
sql = 'select memberlist,displayname from chatroom where chatroomname =?'
|
||||||
cursor.execute(sql,[chatroom])
|
cursor.execute(sql, [chatroom])
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
wxids = result[0].split(';')
|
wxids = result[0].split(';')
|
||||||
names = result[1].split('、')
|
names = result[1].split('、')
|
||||||
@ -194,6 +235,8 @@ def get_chatroom_displayname(chatroom,username):
|
|||||||
for i in wxids:
|
for i in wxids:
|
||||||
print(get_conRemark(i))
|
print(get_conRemark(i))
|
||||||
return names[id]
|
return names[id]
|
||||||
|
|
||||||
|
|
||||||
def get_contacts():
|
def get_contacts():
|
||||||
sql = '''
|
sql = '''
|
||||||
select * from rcontact
|
select * from rcontact
|
||||||
@ -202,11 +245,14 @@ def get_contacts():
|
|||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
result = cursor.fetchall()
|
result = cursor.fetchall()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# rconversation = get_rconversation()
|
# rconversation = get_rconversation()
|
||||||
# for i in rconversation:
|
# for i in rconversation:
|
||||||
# print(i)
|
# print(i)
|
||||||
contacts = get_contacts()
|
# contacts = get_all_message('wxid_vqave8lcp49r22')
|
||||||
for contact in contacts:
|
# for contact in contacts:
|
||||||
print(contact)
|
# print(contact)
|
||||||
|
# [(177325,)] (73546,) (103770,)
|
||||||
|
print(search_send_message(1,1))
|
||||||
|
@ -37,7 +37,7 @@ def mkdir(path):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
mkdir(path+'/emoji')
|
mkdir(path + '/emoji')
|
||||||
# mkdir('..//db_tables')
|
# mkdir('..//db_tables')
|
||||||
'''
|
'''
|
||||||
#! 将wxid使用MD5编码加密
|
#! 将wxid使用MD5编码加密
|
||||||
@ -68,6 +68,7 @@ def get_avator(wxid):
|
|||||||
break
|
break
|
||||||
return Path + '/' + avatar
|
return Path + '/' + avatar
|
||||||
|
|
||||||
|
|
||||||
def read_csv(conRemark):
|
def read_csv(conRemark):
|
||||||
'''
|
'''
|
||||||
:param conRemark: (str) 要导出的联系人备注名
|
:param conRemark: (str) 要导出的联系人备注名
|
||||||
@ -118,9 +119,6 @@ def time_format(timestamp):
|
|||||||
return time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)
|
return time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def IS_5_min(last_m, now_m):
|
def IS_5_min(last_m, now_m):
|
||||||
'''
|
'''
|
||||||
#! 判断两次聊天时间是不是大于五分钟
|
#! 判断两次聊天时间是不是大于五分钟
|
||||||
@ -140,11 +138,6 @@ def judge_type(Type):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''合并word文档到一个文件里'''
|
'''合并word文档到一个文件里'''
|
||||||
|
|
||||||
|
|
||||||
@ -176,6 +169,7 @@ class MyThread(QThread):
|
|||||||
self_text = pyqtSignal(str)
|
self_text = pyqtSignal(str)
|
||||||
ta_text = pyqtSignal(str)
|
ta_text = pyqtSignal(str)
|
||||||
bar = pyqtSignal(int)
|
bar = pyqtSignal(int)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(MyThread, self).__init__()
|
super(MyThread, self).__init__()
|
||||||
self.ta_info = {}
|
self.ta_info = {}
|
||||||
@ -206,7 +200,8 @@ class MyThread(QThread):
|
|||||||
# print(user_data)
|
# print(user_data)
|
||||||
self.total_num = len(user_data)
|
self.total_num = len(user_data)
|
||||||
return user_data
|
return user_data
|
||||||
def create_table(self,doc, isSend):
|
|
||||||
|
def create_table(self, doc, isSend):
|
||||||
'''
|
'''
|
||||||
#! 创建一个1*2表格
|
#! 创建一个1*2表格
|
||||||
#! isSend = 1 (0,0)存聊天内容,(0,1)存头像
|
#! isSend = 1 (0,0)存聊天内容,(0,1)存头像
|
||||||
@ -301,7 +296,7 @@ class MyThread(QThread):
|
|||||||
:return:
|
:return:
|
||||||
'''
|
'''
|
||||||
if 1:
|
if 1:
|
||||||
# try:
|
# try:
|
||||||
Path = f'{path}/emoji/{imgPath}'
|
Path = f'{path}/emoji/{imgPath}'
|
||||||
is_Exist = os.path.exists(Path)
|
is_Exist = os.path.exists(Path)
|
||||||
if not is_Exist:
|
if not is_Exist:
|
||||||
@ -324,7 +319,7 @@ class MyThread(QThread):
|
|||||||
filename = r.lstrip('<title>').rstrip('<')
|
filename = r.lstrip('<title>').rstrip('<')
|
||||||
self.text(doc, isSend, filename, status)
|
self.text(doc, isSend, filename, status)
|
||||||
|
|
||||||
def retract_message(self,doc, isSend, content, status):
|
def retract_message(self, doc, isSend, content, status):
|
||||||
'''
|
'''
|
||||||
#! 显示撤回消息
|
#! 显示撤回消息
|
||||||
:param isSend:
|
:param isSend:
|
||||||
@ -392,7 +387,6 @@ class MyThread(QThread):
|
|||||||
reply_p.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
|
reply_p.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
|
||||||
doc.add_paragraph()
|
doc.add_paragraph()
|
||||||
|
|
||||||
|
|
||||||
def pat_a_pat(self, doc, isSend, content, status):
|
def pat_a_pat(self, doc, isSend, content, status):
|
||||||
'''
|
'''
|
||||||
#! 添加拍一拍信息
|
#! 添加拍一拍信息
|
||||||
@ -471,7 +465,7 @@ class MyThread(QThread):
|
|||||||
now_timestamp = '1600008700000.0'
|
now_timestamp = '1600008700000.0'
|
||||||
for row_index, row in user_data.iterrows():
|
for row_index, row in user_data.iterrows():
|
||||||
self.num += 1
|
self.num += 1
|
||||||
self.bar.emit(int((self.num)/self.total_num*100))
|
self.bar.emit(int((self.num) / self.total_num * 100))
|
||||||
Type = row['type']
|
Type = row['type']
|
||||||
content = row['content']
|
content = row['content']
|
||||||
isSend = row['isSend']
|
isSend = row['isSend']
|
||||||
@ -493,7 +487,7 @@ class MyThread(QThread):
|
|||||||
self.image(doc, isSend, 3, content, imgPath)
|
self.image(doc, isSend, 3, content, imgPath)
|
||||||
elif Type == 47:
|
elif Type == 47:
|
||||||
# print(content)
|
# print(content)
|
||||||
print(imgPath,content)
|
print(imgPath, content)
|
||||||
self.emoji(doc, isSend, content, imgPath)
|
self.emoji(doc, isSend, content, imgPath)
|
||||||
elif Type == 1090519089:
|
elif Type == 1090519089:
|
||||||
self.wx_file(doc, isSend, content, status)
|
self.wx_file(doc, isSend, content, status)
|
||||||
@ -509,9 +503,10 @@ class MyThread(QThread):
|
|||||||
# doc.add_paragraph(str(i))
|
# doc.add_paragraph(str(i))
|
||||||
# print(filename)
|
# print(filename)
|
||||||
doc.save(filename)
|
doc.save(filename)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if 1:
|
if 1:
|
||||||
# try:
|
# try:
|
||||||
self.get_avator()
|
self.get_avator()
|
||||||
conRemark = self.ta_info['conRemark']
|
conRemark = self.ta_info['conRemark']
|
||||||
self.self_text.emit(conRemark)
|
self.self_text.emit(conRemark)
|
||||||
@ -540,7 +535,9 @@ class MyThread(QThread):
|
|||||||
# except Exception as e:
|
# except Exception as e:
|
||||||
# self.self_text.emit('发生异常')
|
# self.self_text.emit('发生异常')
|
||||||
# print(e)
|
# print(e)
|
||||||
#self.self_text.emit(e)
|
# self.self_text.emit(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# # conRemark = '张三' #! 微信备注名
|
# # conRemark = '张三' #! 微信备注名
|
||||||
# n = 100 # ! 分割的文件个数
|
# n = 100 # ! 分割的文件个数
|
||||||
@ -556,7 +553,7 @@ if __name__ == '__main__':
|
|||||||
'wxid': 'wxid_8piw6sb4hvfm22',
|
'wxid': 'wxid_8piw6sb4hvfm22',
|
||||||
'conRemark': '曹雨萱'
|
'conRemark': '曹雨萱'
|
||||||
}
|
}
|
||||||
#wxid_8piw6sb4hvfm22
|
# wxid_8piw6sb4hvfm22
|
||||||
t.self_info = {
|
t.self_info = {
|
||||||
'wxid': 'wxid_27hqbq7vx5hf22',
|
'wxid': 'wxid_27hqbq7vx5hf22',
|
||||||
'conRemark': 'Shuaikang Zhou'
|
'conRemark': 'Shuaikang Zhou'
|
||||||
|
@ -22,6 +22,7 @@ from .chatUi import *
|
|||||||
from ...DataBase import data
|
from ...DataBase import data
|
||||||
from ...ImageBox.ui import MainDemo
|
from ...ImageBox.ui import MainDemo
|
||||||
|
|
||||||
|
|
||||||
class ChatController(QWidget, Ui_Dialog):
|
class ChatController(QWidget, Ui_Dialog):
|
||||||
exitSignal = pyqtSignal()
|
exitSignal = pyqtSignal()
|
||||||
urlSignal = pyqtSignal(QUrl)
|
urlSignal = pyqtSignal(QUrl)
|
||||||
@ -305,7 +306,7 @@ class ChatController(QWidget, Ui_Dialog):
|
|||||||
<img herf= "baidu.com" align="right" src="%s"/>
|
<img herf= "baidu.com" align="right" src="%s"/>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
''' % (imgPath,imgPath)
|
''' % (imgPath, imgPath)
|
||||||
style = 'vertical-align: top'
|
style = 'vertical-align: top'
|
||||||
if isSend:
|
if isSend:
|
||||||
self.right(html, style=style)
|
self.right(html, style=style)
|
||||||
@ -341,27 +342,16 @@ class ChatController(QWidget, Ui_Dialog):
|
|||||||
<td max-width = 300 style="background-color: #fff;border-radius: 4px;"> %s </td>
|
<td max-width = 300 style="background-color: #fff;border-radius: 4px;"> %s </td>
|
||||||
''' % (content)
|
''' % (content)
|
||||||
self.left(html)
|
self.left(html)
|
||||||
def clearImagePath(self,imgpath):
|
|
||||||
path = imgpath.split('/')
|
|
||||||
newPath = '/'.join(path[:-1])+'/'+path[-1][3:]+'.jpg'
|
|
||||||
if os.path.exists(newPath):
|
def hyperlink(self, url: QUrl):
|
||||||
return newPath
|
path = data.clearImagePath(url.path())
|
||||||
newPath = '/'.join(path[:-1]) + '/' + path[-1][3:] + '.png'
|
print(url.path(), path)
|
||||||
if os.path.exists(newPath):
|
|
||||||
return newPath
|
|
||||||
newPath = '/'.join(path[:-1]) + '/' + path[-1]+ 'hd'
|
|
||||||
if os.path.exists(newPath):
|
|
||||||
return newPath
|
|
||||||
return imgpath
|
|
||||||
def hyperlink(self, url:QUrl):
|
|
||||||
path = self.clearImagePath(url.path())
|
|
||||||
print(url.path(),path)
|
|
||||||
self.imagebox = MainDemo()
|
self.imagebox = MainDemo()
|
||||||
self.imagebox.show()
|
self.imagebox.show()
|
||||||
self.imagebox.box.set_image(path)
|
self.imagebox.box.set_image(path)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def right(self, content, style='vertical-align: middle'):
|
def right(self, content, style='vertical-align: middle'):
|
||||||
html = '''
|
html = '''
|
||||||
<div>
|
<div>
|
||||||
|
@ -102,7 +102,7 @@ class MainWinController(QMainWindow, Ui_Dialog):
|
|||||||
|
|
||||||
def about(self):
|
def about(self):
|
||||||
QMessageBox.about(self, "关于",
|
QMessageBox.about(self, "关于",
|
||||||
"关于作者\n姓名:周帅康\n联系方式:863909694"
|
"关于作者\n姓名:周帅康\n邮箱:lc863854@mail.nwpu.edu.cn"
|
||||||
)
|
)
|
||||||
|
|
||||||
def setviewVisible(self, view):
|
def setviewVisible(self, view):
|
||||||
|
Loading…
Reference in New Issue
Block a user