From 6f5063f827d2a9112f7bd9f712832c0c7f7750e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?=
<101191390+HIllya51@users.noreply.github.com>
Date: Sat, 18 May 2024 17:09:43 +0800
Subject: [PATCH] termbank
Update LunaTranslator.py
---
.../LunaTranslator/LunaTranslator.py | 3 +-
.../LunaTranslator/cishu/yomichan.py | 41 +++++++++++++++++++
.../files/defaultconfig/config.json | 22 ++++++++++
3 files changed, 65 insertions(+), 1 deletion(-)
create mode 100644 LunaTranslator/LunaTranslator/cishu/yomichan.py
diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py
index b2aa6e02..8721af15 100644
--- a/LunaTranslator/LunaTranslator/LunaTranslator.py
+++ b/LunaTranslator/LunaTranslator/LunaTranslator.py
@@ -452,7 +452,6 @@ class MAINUI:
if globalconfig["sourcestatus2"]["texthook"]["use"]:
self.textsource = texthook(pids, hwnd, pexe)
- # @threader
def starttextsource(self, use=None, checked=True):
self.translation_ui.showhidestate = False
self.translation_ui.refreshtooliconsignal.emit()
@@ -547,6 +546,7 @@ class MAINUI:
return None
return aclass(classname)
+ @threader
def prepare(self, now=None, _=None):
self.commonloader("fanyi", self.translators, self.fanyiinitmethod, now)
@@ -574,6 +574,7 @@ class MAINUI:
except:
print_exc()
+ @threader
def startxiaoxueguan(self, type_=None, _=None):
self.commonloader("cishu", self.cishus, self.cishuinitmethod, type_)
diff --git a/LunaTranslator/LunaTranslator/cishu/yomichan.py b/LunaTranslator/LunaTranslator/cishu/yomichan.py
new file mode 100644
index 00000000..3567528f
--- /dev/null
+++ b/LunaTranslator/LunaTranslator/cishu/yomichan.py
@@ -0,0 +1,41 @@
+import os
+import requests
+from urllib.parse import quote
+import re,json
+from myutils.proxy import getproxy
+from cishu.cishubase import cishubase
+
+
+class yomichan(cishubase):
+ def init(self):
+ self.sql = None
+
+ path = self.config["path"]
+ self.datas=[]
+ for f in os.listdir(path):
+ if f.startswith('term_bank_') and f.endswith('.json'):
+ with open(os.path.join(path,f),'r',encoding='utf8') as ff:
+ self.datas+=json.loads(ff.read())
+
+ def search(self, word):
+ best=[]
+ normal=[]
+ bad=[]
+ for item in self.datas:
+ if item[0]==word:
+ best.append(item)
+ elif item[0].startswith(word) or item[0].endswith(word):
+ normal.append(item)
+ elif word in item[0]:
+ bad.append(item)
+
+ if len(bad)+len(best)+len(normal)==0:return
+ html=''
+ for item in best+normal+bad:
+ word=item[0]
+ hira=item[1]
+ explain=item[5][0].replace("\n","
")
+ html+=f'