diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2024-05-01 18:25:22 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-05-01 18:58:28 +0200 |
commit | 11fe88bb40b9a18583798e15fd6ab4f88cb5aaf1 (patch) | |
tree | 301ae3c64ba9fa006a7794cf43860622c19a909e /searxng_extra | |
parent | c8d0b6529b616aa33678afa10edc414b460ea017 (diff) | |
download | searxng-11fe88bb40b9a18583798e15fd6ab4f88cb5aaf1.tar.gz searxng-11fe88bb40b9a18583798e15fd6ab4f88cb5aaf1.zip |
[fix] update wikidata units - remove URL prefix from Q-name
Sometimes the URL prefix switches from a http to a https, this patch harden the
code that removes the URL prefix from wikidata Q-name, issue has been reported
in [1].
[1] https://github.com/searxng/searxng/pull/3437#issuecomment-2082121730
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searxng_extra')
-rwxr-xr-x | searxng_extra/update/update_wikidata_units.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/searxng_extra/update/update_wikidata_units.py b/searxng_extra/update/update_wikidata_units.py index f384df749..96326874a 100755 --- a/searxng_extra/update/update_wikidata_units.py +++ b/searxng_extra/update/update_wikidata_units.py @@ -51,16 +51,18 @@ WHERE ORDER BY ?item DESC(?rank) ?symbol """ -_wikidata_url = "https://www.wikidata.org/entity/" - def get_data(): results = collections.OrderedDict() response = wikidata.send_wikidata_query(SARQL_REQUEST) for unit in response['results']['bindings']: - name = unit['item']['value'].replace(_wikidata_url, '') + symbol = unit['symbol']['value'] - si_name = unit.get('tosiUnit', {}).get('value', '').replace(_wikidata_url, '') + name = unit['item']['value'].rsplit('/', 1)[1] + si_name = unit.get('tosiUnit', {}).get('value', '') + if si_name: + si_name = si_name.rsplit('/', 1)[1] + to_si_factor = unit.get('tosi', {}).get('value', '') if name not in results: # ignore duplicate: always use the first one |