From 169829fa1b52c96b35cff2f9bf7e98fe0304c100 Mon Sep 17 00:00:00 2001 From: SwimmingLiu Date: Mon, 16 Sep 2024 20:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=98=B5=E7=A7=B0=E3=80=81=E8=AF=B4?= =?UTF-8?q?=E8=AF=B4=E5=86=85=E5=AE=B9=E3=80=81=E8=AF=84=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E5=BD=93=E4=B8=AD=E7=9A=84QQ=E8=A1=A8=E6=83=85=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=B8=BAimg=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 7 +++++++ util/ToolsUtil.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/main.py b/main.py index bdd48fb..3cbe256 100644 --- a/main.py +++ b/main.py @@ -73,7 +73,11 @@ def render_html(shuoshuo_path, zhuanfa_path): if len(content_lst) == 1: continue nickname = content_lst[0] + # 将nickname当中的QQ表情替换为img标签 + nickname = re.sub(r'\[em\](.*?)\[/em\]', Tools.replace_em_to_img, nickname) message = content_lst[1] + # 将message当中的QQ表情替换为img标签 + message = re.sub(r'\[em\](.*?)\[/em\]', Tools.replace_em_to_img, message) image_html = '
' for img_url in img_url_lst: if img_url and img_url.startswith('http'): @@ -88,6 +92,9 @@ def render_html(shuoshuo_path, zhuanfa_path): comments = eval(comments) for comment in comments: comment_create_time, comment_content, comment_nickname, comment_uin = comment + # 将评论人昵称和评论内容当中的QQ表情替换为img标签 + comment_nickname = re.sub(r'\[em\](.*?)\[/em\]', Tools.replace_em_to_img, comment_nickname) + comment_content = re.sub(r'\[em\](.*?)\[/em\]', Tools.replace_em_to_img, comment_content) comment_avatar_url = f"https://q.qlogo.cn/headimg_dl?dst_uin={comment_uin}&spec=640&img_type=jpg" comment_html += comment_template.format( avatar_url=comment_avatar_url, diff --git a/util/ToolsUtil.py b/util/ToolsUtil.py index 83362f3..4c146cb 100644 --- a/util/ToolsUtil.py +++ b/util/ToolsUtil.py @@ -229,3 +229,9 @@ def read_txt_file(workdir, file_name): return None +# QQ空间表情替换 [em]xxx[/em] 为 +def replace_em_to_img(match): + # 获取匹配的 xxx 部分 + emoji_code = match.group(1) + return f'{emoji_code}' +