将昵称、说说内容、评论区当中的QQ表情替换为img标签

This commit is contained in:
SwimmingLiu 2024-09-16 20:16:38 +08:00
parent 3e331172c3
commit 169829fa1b
2 changed files with 13 additions and 0 deletions

View File

@ -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 = '<div class="image">'
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,

View File

@ -229,3 +229,9 @@ def read_txt_file(workdir, file_name):
return None
# QQ空间表情替换 [em]xxx[/em] 为 <img src="http://qzonestyle.gtimg.cn/qzone/em/xxx.gif">
def replace_em_to_img(match):
# 获取匹配的 xxx 部分
emoji_code = match.group(1)
return f'<img src="http://qzonestyle.gtimg.cn/qzone/em/{emoji_code}.gif" alt="{emoji_code}">'