Skip to content

Commit

Permalink
improves
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Aug 22, 2024
1 parent 61c4c9c commit da872c6
Showing 1 changed file with 49 additions and 44 deletions.
93 changes: 49 additions & 44 deletions skg/skgbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ngwidgets.input_webserver import InputWebserver, InputWebSolution
from ngwidgets.webserver import WebserverConfig
from ngwidgets.widgets import Lang, Link
from nicegui import Client, ui
from nicegui import Client, ui, run
from wikibot3rd.wikiuser import WikiUser

from skg.orcid import ORCID
Expand Down Expand Up @@ -85,6 +85,7 @@ def __init__(self, webserver: SkgBrowser, client: Client):
self.markup_names = ["-", "bibtex", "scite", "smw"]
self.markup_name = self.markup_names[1]
self.sotsog = SotSog.instance
self.sotsog.options.open_browser=False

def configure_menu(self):
"""
Expand Down Expand Up @@ -123,49 +124,53 @@ async def onSearchButton(self, _msg):
"""
handle button to search for terms
"""
try:
self.results.content = ""
self.markup.content = ""
terms = self.searchTerms.value.split("\n")
self.messages.content = "Searching"
delim = ""
for term in terms:
if term:
msg = f"... {term}\n"
self.messages.content += msg
if self.markup_name == "-":
self.options.markup_names = []
else:
self.options.markup_names = [self.markup_name]
search_result = self.sotsog.search([term], self.options)
items = search_result.items
rmarkup = ""
if len(items) == 0:
# TODO check google search
# https://pypi.org/project/googlesearch-python/
params = parse.urlencode({"q": term})
search_url = f"https://www.google.com/search?{params}"
rmarkup = Link.create(
search_url,
term,
"not found",
target="_blank",
style="color:red",
)
else:
for i, item in enumerate(items):
rmarkup += self.createItemLink(item, term, i)
if len(item.markups) > 0:
markups = ""
for _markup_name, markup in item.markups.items():
markups += markup
self.markup.content += f"<pre>{markups}</pre>"
# break
self.results.content += delim + rmarkup
delim = "<br>"

except BaseException as ex:
self.handle_exception(ex)
await run.io_bound(self.do_search)

def do_search(self):
with self.content_div:
try:
self.results.content = ""
self.markup.content = ""
terms = self.searchTerms.value.split("\n")
self.messages.content = "Searching"
delim = ""
for term in terms:
if term:
msg = f"... {term}\n"
self.messages.content += msg
if self.markup_name == "-":
self.sotsog.options.markup_names = []
else:
self.sotsog.options.markup_names = [self.markup_name]
search_result = self.sotsog.search([term], self.sotsog.options)
items = search_result.items
rmarkup = ""
if len(items) == 0:
# TODO check google search
# https://pypi.org/project/googlesearch-python/
params = parse.urlencode({"q": term})
search_url = f"https://www.google.com/search?{params}"
rmarkup = Link.create(
search_url,
term,
"not found",
target="_blank",
style="color:red",
)
else:
for i, item in enumerate(items):
rmarkup += self.createItemLink(item, term, i)
if len(item.markups) > 0:
markups = ""
for _markup_name, markup in item.markups.items():
markups += markup
self.markup.content += f"<pre>{markups}</pre>"
# break
self.results.content += delim + rmarkup
delim = "<br>"

except BaseException as ex:
self.handle_exception(ex)

def addLanguageSelect(self):
"""
Expand Down

0 comments on commit da872c6

Please sign in to comment.