searx.network: refactoring

This commit is contained in:
Alexandre Flament 2023-08-18 12:16:02 +00:00 committed by Alexandre Flament
parent d4e21dec26
commit 45c217ff6e
24 changed files with 2320 additions and 888 deletions

View file

@ -207,7 +207,6 @@ def initialize():
def fetch_wikidata_descriptions():
print('Fetching wikidata descriptions')
searx.network.set_timeout_for_thread(60)
result = wikidata.send_wikidata_query(
SPARQL_DESCRIPTION.replace('%IDS%', IDS).replace('%LANGUAGES_SPARQL%', LANGUAGES_SPARQL)
)
@ -356,6 +355,7 @@ def get_output():
return output
@searx.network.networkcontext_decorator(timeout=60)
def main():
initialize()
fetch_wikidata_descriptions()

View file

@ -76,6 +76,7 @@ lang2emoji = {
}
@network.networkcontext_decorator(timeout=60)
def main():
load_engines(settings['engines'])
# traits_map = EngineTraitsMap.from_data()
@ -86,7 +87,6 @@ def main():
def fetch_traits_map():
"""Fetchs supported languages for each engine and writes json file with those."""
network.set_timeout_for_thread(10.0)
def log(msg):
print(msg)

View file

@ -45,7 +45,7 @@ Output file: :origin:`searx/data/osm_keys_tags` (:origin:`CI Update data ...
import json
import collections
from searx.network import set_timeout_for_thread
from searx.network import networkcontext_decorator
from searx.engines import wikidata, set_loggers
from searx.sxng_locales import sxng_locales
from searx.engines.openstreetmap import get_key_rank, VALUE_TO_LINK
@ -203,12 +203,15 @@ def optimize_keys(data):
return data
if __name__ == '__main__':
set_timeout_for_thread(60)
@networkcontext_decorator(timeout=60)
def main():
result = {
'keys': optimize_keys(get_keys()),
'tags': optimize_tags(get_tags()),
}
with DATA_FILE.open('w', encoding="utf8") as f:
json.dump(result, f, indent=4, sort_keys=True, ensure_ascii=False)
if __name__ == '__main__':
main()