mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-21 01:52:35 +08:00
把emoji变成url
This commit is contained in:
parent
b2df183dc6
commit
54fec335a0
@ -16,7 +16,7 @@ from ..person import MePC
|
||||
from ..util import path
|
||||
import shutil
|
||||
from ..util.compress_content import parser_reply
|
||||
from ..util.emoji import get_emoji, get_emoji_path
|
||||
from ..util.emoji import get_emoji, get_emoji_path, get_emoji_url
|
||||
from ..util.image import get_image_path, get_image
|
||||
|
||||
os.makedirs('./data/聊天记录', exist_ok=True)
|
||||
@ -345,8 +345,9 @@ class ChildThread(QThread):
|
||||
displayname = MePC().name if is_send else self.contact.remark
|
||||
displayname = escape_js_and_html(displayname)
|
||||
if self.output_type == Output.HTML:
|
||||
emoji_path = get_emoji_path(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
|
||||
emoji_path = './emoji/' + os.path.basename(emoji_path)
|
||||
# emoji_path = get_emoji_path(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
|
||||
# emoji_path = './emoji/' + os.path.basename(emoji_path)
|
||||
emoji_path = get_emoji_url(str_content, thumb=True)
|
||||
doc.write(
|
||||
f'''{{ type:{3}, text: '{emoji_path}',is_send:{is_send},avatar_path:'{avatar}',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
|
||||
)
|
||||
@ -750,3 +751,28 @@ class OutputImageChild(QThread):
|
||||
self.progressSignal.emit(1)
|
||||
self.okSingal.emit(47)
|
||||
print('图片子线程完成')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from app.DataBase import micro_msg_db, misc_db
|
||||
from app.person import ContactPC
|
||||
from PyQt5.QtGui import QGuiApplication
|
||||
app = QGuiApplication([])
|
||||
contact_info_list = micro_msg_db.get_contact_by_username("wxid_lhbdvh3cnn4h22")
|
||||
contact_info = {
|
||||
'UserName': contact_info_list[0],
|
||||
'Alias': contact_info_list[1],
|
||||
'Type': contact_info_list[2],
|
||||
'Remark': contact_info_list[3],
|
||||
'NickName': contact_info_list[4],
|
||||
'smallHeadImgUrl': contact_info_list[7]
|
||||
}
|
||||
contact = ContactPC(contact_info)
|
||||
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
||||
contact.set_avatar(contact.smallHeadImgBLOG)
|
||||
mess = {1: True, 3: True, 34: True, 43: True, 47: True, 10000: True}
|
||||
MePC().name = "无题"
|
||||
MePC().wx_dir = r"C:\Users\HUAWEI\Documents\WeChat Files\wxid_05rvkbftizq822"
|
||||
MePC().wxid = "wxid_05rvkbftizq822"
|
||||
ChildThread(contact, 2, mess).to_html_()
|
||||
app.quit()
|
@ -93,7 +93,8 @@ class Emotion:
|
||||
if lock.locked():
|
||||
lock.release()
|
||||
|
||||
def get_emoji_url(self, md5: str, thumb: bool):
|
||||
def get_emoji_url(self, md5: str, thumb: bool) -> str | bytes:
|
||||
'''供下载用,返回可能是url可能是bytes'''
|
||||
if thumb:
|
||||
sql = '''
|
||||
select
|
||||
@ -129,6 +130,33 @@ class Emotion:
|
||||
finally:
|
||||
lock.release()
|
||||
|
||||
def get_emoji_URL(self, md5: str, thumb: bool):
|
||||
'''只管url,另外的不管'''
|
||||
if thumb:
|
||||
sql = '''
|
||||
select
|
||||
case
|
||||
when thumburl is NULL or thumburl = '' then cdnurl
|
||||
else thumburl
|
||||
end as selected_url
|
||||
from CustomEmotion
|
||||
where md5 = ?
|
||||
'''
|
||||
else:
|
||||
sql = '''
|
||||
select CDNUrl
|
||||
from CustomEmotion
|
||||
where md5 = ?
|
||||
'''
|
||||
try:
|
||||
lock.acquire(True)
|
||||
self.cursor.execute(sql, [md5])
|
||||
return self.cursor.fetchone()[0]
|
||||
except:
|
||||
return ""
|
||||
finally:
|
||||
lock.release()
|
||||
|
||||
def close(self):
|
||||
if self.open_flag:
|
||||
try:
|
||||
@ -187,6 +215,7 @@ def get_most_emoji(messages):
|
||||
|
||||
|
||||
def get_emoji(xml_string, thumb=True, output_path=root_path) -> str:
|
||||
"""供下载用"""
|
||||
try:
|
||||
emoji_info = parser_xml(xml_string)
|
||||
md5 = emoji_info['md5']
|
||||
@ -243,6 +272,20 @@ def get_emoji_path(xml_string, thumb=True, output_path=root_path) -> str:
|
||||
logger.error(traceback.format_exc())
|
||||
output_path = os.path.join(output_path, "404.png")
|
||||
return output_path
|
||||
|
||||
def get_emoji_url(xml_string, thumb=True) -> str:
|
||||
"""不管下载,只返回url"""
|
||||
try:
|
||||
emoji_info = parser_xml(xml_string)
|
||||
md5 = emoji_info['md5']
|
||||
url = emoji_info["thumburl" if thumb else "cdnurl"]
|
||||
if not url or url == '':
|
||||
url = Emotion().get_emoji_URL(md5=md5, thumb=thumb)
|
||||
return url
|
||||
except:
|
||||
logger.error(traceback.format_exc())
|
||||
output_path = os.path.join(output_path, "404.png")
|
||||
return output_path
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user