mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-21 01:52:35 +08:00
导出word文档
This commit is contained in:
parent
f5989290f9
commit
3a5bd4d5d5
@ -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))
|
||||
|
@ -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('<title>').rstrip('<')
|
||||
self.text(doc, isSend, filename, status)
|
||||
|
||||
def retract_message(self,doc, isSend, content, status):
|
||||
def retract_message(self, doc, isSend, content, status):
|
||||
'''
|
||||
#! 显示撤回消息
|
||||
:param isSend:
|
||||
@ -392,7 +387,6 @@ class MyThread(QThread):
|
||||
reply_p.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
|
||||
doc.add_paragraph()
|
||||
|
||||
|
||||
def pat_a_pat(self, doc, isSend, content, status):
|
||||
'''
|
||||
#! 添加拍一拍信息
|
||||
@ -471,7 +465,7 @@ class MyThread(QThread):
|
||||
now_timestamp = '1600008700000.0'
|
||||
for row_index, row in user_data.iterrows():
|
||||
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']
|
||||
content = row['content']
|
||||
isSend = row['isSend']
|
||||
@ -493,7 +487,7 @@ class MyThread(QThread):
|
||||
self.image(doc, isSend, 3, content, imgPath)
|
||||
elif Type == 47:
|
||||
# print(content)
|
||||
print(imgPath,content)
|
||||
print(imgPath, content)
|
||||
self.emoji(doc, isSend, content, imgPath)
|
||||
elif Type == 1090519089:
|
||||
self.wx_file(doc, isSend, content, status)
|
||||
@ -509,9 +503,10 @@ class MyThread(QThread):
|
||||
# doc.add_paragraph(str(i))
|
||||
# print(filename)
|
||||
doc.save(filename)
|
||||
|
||||
def run(self):
|
||||
if 1:
|
||||
# try:
|
||||
# try:
|
||||
self.get_avator()
|
||||
conRemark = self.ta_info['conRemark']
|
||||
self.self_text.emit(conRemark)
|
||||
@ -540,7 +535,9 @@ class MyThread(QThread):
|
||||
# except Exception as e:
|
||||
# self.self_text.emit('发生异常')
|
||||
# print(e)
|
||||
#self.self_text.emit(e)
|
||||
# self.self_text.emit(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# # conRemark = '张三' #! 微信备注名
|
||||
# n = 100 # ! 分割的文件个数
|
||||
@ -556,7 +553,7 @@ if __name__ == '__main__':
|
||||
'wxid': 'wxid_8piw6sb4hvfm22',
|
||||
'conRemark': '曹雨萱'
|
||||
}
|
||||
#wxid_8piw6sb4hvfm22
|
||||
# wxid_8piw6sb4hvfm22
|
||||
t.self_info = {
|
||||
'wxid': 'wxid_27hqbq7vx5hf22',
|
||||
'conRemark': 'Shuaikang Zhou'
|
||||
|
@ -22,6 +22,7 @@ from .chatUi import *
|
||||
from ...DataBase import data
|
||||
from ...ImageBox.ui import MainDemo
|
||||
|
||||
|
||||
class ChatController(QWidget, Ui_Dialog):
|
||||
exitSignal = pyqtSignal()
|
||||
urlSignal = pyqtSignal(QUrl)
|
||||
@ -305,7 +306,7 @@ class ChatController(QWidget, Ui_Dialog):
|
||||
<img herf= "baidu.com" align="right" src="%s"/>
|
||||
</a>
|
||||
</td>
|
||||
''' % (imgPath,imgPath)
|
||||
''' % (imgPath, imgPath)
|
||||
style = 'vertical-align: top'
|
||||
if isSend:
|
||||
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>
|
||||
''' % (content)
|
||||
self.left(html)
|
||||
def clearImagePath(self,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 hyperlink(self, url:QUrl):
|
||||
path = self.clearImagePath(url.path())
|
||||
print(url.path(),path)
|
||||
|
||||
|
||||
|
||||
def hyperlink(self, url: QUrl):
|
||||
path = data.clearImagePath(url.path())
|
||||
print(url.path(), path)
|
||||
self.imagebox = MainDemo()
|
||||
self.imagebox.show()
|
||||
self.imagebox.box.set_image(path)
|
||||
|
||||
|
||||
|
||||
def right(self, content, style='vertical-align: middle'):
|
||||
html = '''
|
||||
<div>
|
||||
|
@ -102,7 +102,7 @@ class MainWinController(QMainWindow, Ui_Dialog):
|
||||
|
||||
def about(self):
|
||||
QMessageBox.about(self, "关于",
|
||||
"关于作者\n姓名:周帅康\n联系方式:863909694"
|
||||
"关于作者\n姓名:周帅康\n邮箱:lc863854@mail.nwpu.edu.cn"
|
||||
)
|
||||
|
||||
def setviewVisible(self, view):
|
||||
|
Loading…
Reference in New Issue
Block a user