diff --git a/LunaTranslator/LunaTranslator/cishu/mojidict.py b/LunaTranslator/LunaTranslator/cishu/mojidict.py index b480fb66..496c93de 100644 --- a/LunaTranslator/LunaTranslator/cishu/mojidict.py +++ b/LunaTranslator/LunaTranslator/cishu/mojidict.py @@ -1,45 +1,626 @@ -import requests +import requests, re, json from myutils.proxy import getproxy from cishu.cishubase import cishubase +def mojiclicksearch(word): + + headers = { + "accept": "*/*", + "accept-language": "zh-CN,zh;q=0.9,ar;q=0.8,sq;q=0.7,ru;q=0.6", + "content-type": "text/plain", + "origin": "https://www.mojidict.com", + "priority": "u=1, i", + "referer": "https://www.mojidict.com/", + "sec-ch-ua": '"Chromium";v="124", "Google Chrome";v="124", "Not-A.Brand";v="99"', + "sec-ch-ua-mobile": "?0", + "sec-ch-ua-platform": '"Windows"', + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-site", + "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", + } + data = json.dumps( + { + "searchText": word, + "langEnv": "zh-CN_ja", + "_SessionToken": "r:718e90d7837c22ac48f71d000d0a62f4", + "_ClientVersion": "js3.4.1", + "_ApplicationId": "E62VyFVLMiW7kvbtVq3p", + "g_os": "PCWeb", + "g_ver": "v4.8.1.20240522", + "_InstallationId": "101241e8-4004-40b2-a040-f6839ed76d32", + }, + ensure_ascii=False, + ).encode() + + response = requests.post( + "https://api.mojidict.com/parse/functions/word-clickSearchV2", + headers=headers, + data=data, + proxies=getproxy(), + ) + + result = response.json()["result"]["result"] + word = result["word"] + + subdetails = result["subdetails"] + collect = [] + relaid = [] + + for subdetail in subdetails: + title = subdetail["title"] + # print(title,subdetail) + + good = False + for i in range(len(relaid)): + if relaid[i] == subdetail["relaId"]: + if subdetail["lang"] == "zh-CN": + collect[i] = title + collect[i] + elif subdetail["lang"] == "ja": + title = f"({title})" + collect[i] = collect[i] + title + good = True + if not good: + collect.append(title) + relaid.append(subdetail["relaId"]) + # print('\n'.join(collect)) + excerpt = word[0]["excerpt"] + accent = word[0]["accent"] + spell = word[0]["spell"] + pron = word[0]["pron"] + style = r""" + + + """ + spell = f"{spell}|{pron}{accent}" + spell = f'
{_type}
' + + for i in range(len(collect)): + collect[i] = f"{i+1}. {collect[i]}
" + detail = f"""