mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
some
This commit is contained in:
parent
d84757673c
commit
dfbe50de38
@ -1,14 +1,97 @@
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
import re, threading
|
||||
from cishu.cishubase import cishubase
|
||||
from myutils.utils import get_element_by
|
||||
from myutils.utils import get_element_by, simplehtmlparser_all
|
||||
|
||||
|
||||
class jisho(cishubase):
|
||||
|
||||
def search(self, word):
|
||||
url = "https://jisho.org/search/{}".format(quote(word))
|
||||
def generatehtml_tabswitch(self, allres):
|
||||
btns = []
|
||||
contents = []
|
||||
idx = 0
|
||||
for title, res in allres:
|
||||
idx += 1
|
||||
btns.append(
|
||||
f"""<button type="button" onclick="onclickbtn_xxxxxx_internal('buttonid_xxxxx_internal{idx}')" id="buttonid_xxxxx_internal{idx}" class="tab-button_xxxx_internal" data-tab="tab_xxxxx_internal{idx}">{title}</button>"""
|
||||
)
|
||||
contents.append(
|
||||
f"""<div id="tab_xxxxx_internal{idx}" class="tab-pane_xxxxx_internal">{res}</div>"""
|
||||
)
|
||||
commonstyle = """
|
||||
<script>
|
||||
function onclickbtn_xxxxxx_internal(_id) {
|
||||
tabPanes = document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-pane_xxxxx_internal');
|
||||
tabButtons = document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal');
|
||||
for (i = 0; i < tabButtons.length; i++)
|
||||
tabButtons[i].classList.remove('active');
|
||||
for (i = 0; i < tabPanes.length; i++)
|
||||
tabPanes[i].classList.remove('active');
|
||||
|
||||
document.getElementById(_id).classList.add('active');
|
||||
|
||||
tabId = document.getElementById(_id).getAttribute('data-tab');
|
||||
tabPane = document.getElementById(tabId);
|
||||
tabPane.classList.add('active');
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.centerdiv_xxxxxx_internal {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
.tab-widget_xxxxxx_internal .tab-button_xxxxxx_internals_xxxxxx_internal {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.tab-widget_xxxxxx_internal .tab-button_xxxx_internal {
|
||||
padding: 10px 20px;
|
||||
background-color: #cccccccc;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.tab-widget_xxxxxx_internal .tab-button_xxxx_internal.active {
|
||||
background-color: #cccccc44;
|
||||
}
|
||||
|
||||
.tab-widget_xxxxxx_internal .tab-content_xxxxxx_internal .tab-pane_xxxxx_internal {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-widget_xxxxxx_internal .tab-content_xxxxxx_internal .tab-pane_xxxxx_internal.active {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
"""
|
||||
|
||||
res = f"""
|
||||
{commonstyle}
|
||||
<div class="tab-widget_xxxxxx_internal">
|
||||
|
||||
<div class="centerdiv_xxxxxx_internal"><div>
|
||||
{''.join(btns)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="tab-content_xxxxxx_internal">
|
||||
{''.join(contents)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if(document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal').length)
|
||||
document.querySelectorAll('.tab-widget_xxxxxx_internal .tab-button_xxxx_internal')[0].click()
|
||||
</script>
|
||||
"""
|
||||
return res
|
||||
|
||||
def paradown(self, word, key, saver):
|
||||
|
||||
link = "https://jisho.org/{}/{}".format(key, quote(word))
|
||||
url = link
|
||||
html = requests.get(
|
||||
url,
|
||||
proxies=self.proxy,
|
||||
@ -27,8 +110,50 @@ class jisho(cishubase):
|
||||
)
|
||||
.replace(get_element_by("id", "other_dictionaries", html), "")
|
||||
)
|
||||
for link in simplehtmlparser_all(
|
||||
res, "a", '<a class="concept_audio concept_light-status_link"'
|
||||
):
|
||||
res = res.replace(link, "")
|
||||
for link in simplehtmlparser_all(
|
||||
res, "a", '<a class="concept_light-status_link"'
|
||||
):
|
||||
res = res.replace(link, "")
|
||||
for link in simplehtmlparser_all(res, "a", '<a href="#"'):
|
||||
res = res.replace(link, "")
|
||||
|
||||
ss = re.search('href="https://assets.jisho.org/assets/application(.*)"', html)
|
||||
stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text
|
||||
if key == "search":
|
||||
ss = re.search(
|
||||
'href="https://assets.jisho.org/assets/application(.*)"', html
|
||||
)
|
||||
stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text
|
||||
saver["style"] = stl
|
||||
saver["primary"] = get_element_by("id", "main_results", res) + res.replace(
|
||||
get_element_by("id", "main_results", res),
|
||||
get_element_by("id", "primary", res),
|
||||
)
|
||||
saver["secondary"] = res.replace(
|
||||
get_element_by("id", "main_results", res),
|
||||
get_element_by("id", "secondary", res),
|
||||
)
|
||||
else:
|
||||
saver[key] = res
|
||||
|
||||
return f"<style>{stl}</style>{res}"
|
||||
def search(self, word):
|
||||
|
||||
ts = []
|
||||
saver = {}
|
||||
for key in ("word", "search"):
|
||||
ts.append(threading.Thread(target=self.paradown, args=(word, key, saver)))
|
||||
ts[-1].start()
|
||||
for t in ts:
|
||||
t.join()
|
||||
res = []
|
||||
if saver.get("word"):
|
||||
res.append(("Word", saver["word"]))
|
||||
if saver.get("primary"):
|
||||
res.append(("Words", saver["primary"]))
|
||||
if saver.get("secondary"):
|
||||
res.append(("Others", saver["secondary"]))
|
||||
return "<style>{}</style>".format(
|
||||
saver.get("style", "")
|
||||
) + self.generatehtml_tabswitch(res)
|
||||
|
@ -1021,4 +1021,7 @@ def get_element_by(attr, attrv, html):
|
||||
"""Return the content of the tag with the specified id in the passed HTML document"""
|
||||
parser = IDParser(attr, attrv)
|
||||
parser.loads(html)
|
||||
return parser.get_result()
|
||||
res = parser.get_result()
|
||||
if res is None:
|
||||
return ""
|
||||
return res
|
||||
|
@ -24,7 +24,7 @@
|
||||
{{screenshot}}
|
||||
</div>
|
||||
|
||||
<div id="remarks" class="centerdiv remark-div">
|
||||
<div id="remarks" class="centerdiv centertext remark-div">
|
||||
{{remarks}}
|
||||
</div>
|
||||
|
||||
|
@ -9,6 +9,10 @@
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.centertext {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
.centerdiv img {
|
||||
max-width: 100%;
|
||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
||||
|
||||
set(VERSION_MAJOR 5)
|
||||
set(VERSION_MINOR 50)
|
||||
set(VERSION_PATCH 2)
|
||||
set(VERSION_PATCH 3)
|
||||
|
||||
add_library(pch pch.cpp)
|
||||
target_precompile_headers(pch PUBLIC pch.h)
|
||||
|
Loading…
x
Reference in New Issue
Block a user