qwfqwf
This commit is contained in:
38
main.py
38
main.py
@@ -35,6 +35,38 @@ models.Base.metadata.create_all(bind=engine)
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
def is_chinese(char):
|
||||
"""检查字符是否为中文字符。"""
|
||||
return '\u4e00' <= char <= '\u9fff'
|
||||
|
||||
def convert_special_chars_to_emoji(input_string):
|
||||
output = []
|
||||
for char in input_string:
|
||||
# 检查字符是否为 ASCII 字符或中文字符
|
||||
if ord(char) <= 127 or is_chinese(char):
|
||||
# ASCII 字符或中文字符直接添加
|
||||
output.append(char)
|
||||
else:
|
||||
# 获取 Unicode 代码点
|
||||
code_point = f"{ord(char):X}"
|
||||
# 将代码点转换为 emoji 代码点形式
|
||||
emoji_representation = f"[@emoji={code_point}]"
|
||||
# 将非中文且非 ASCII 字符替换为 emoji 代码点形式
|
||||
output.append(emoji_representation)
|
||||
|
||||
# 将列表中的字符组合成一个字符串
|
||||
return ''.join(output)
|
||||
|
||||
# 示例字符串
|
||||
input_string = "aaa取暖桌ᯤ⁵ᴳ"
|
||||
|
||||
# 调用函数
|
||||
output_string = convert_special_chars_to_emoji(input_string)
|
||||
|
||||
print("输入字符串:", input_string)
|
||||
print("输出字符串:", output_string)
|
||||
|
||||
|
||||
# 转换emoji字符串为[]
|
||||
def transOldemoji(oldEmoji=None):
|
||||
# oldEmoji = "异度世界🤖"
|
||||
@@ -168,6 +200,8 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
||||
print(newtext)
|
||||
# 处理emoji转为[@emoji=1f916] 格式
|
||||
newtext=transOldemoji(newtext)
|
||||
# 不是 ASCII 字符,则获取该字符的 Unicode 代码点
|
||||
newtext = convert_special_chars_to_emoji(input_string)
|
||||
matches = re.findall(pattern, newtext)
|
||||
print("matches", matches)
|
||||
matchesString = None
|
||||
@@ -192,8 +226,8 @@ def h5group(nickname, db: Session = Depends(get_db)):
|
||||
new_wxid = None
|
||||
allFriend = WXBotService.get_address_list(config.account_wxid)
|
||||
for friendItem in allFriend['data']["contactList"]:
|
||||
# if friendItem['nickname'] == matchesString:
|
||||
if matchesString in friendItem['nickname']:
|
||||
if friendItem['nickname'] == matchesString:
|
||||
# if matchesString in friendItem['nickname']:
|
||||
new_wxid = friendItem['wxid']
|
||||
else:
|
||||
# print('通过nickname查不到wxid')
|
||||
|
||||
Reference in New Issue
Block a user