From 8f0eef73959e136cec9a8d265e8d448fe0975457 Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Sun, 23 Jan 2022 22:29:57 +0100 Subject: [PATCH] Fix handling of empty coordinates. --- bots/sledrun_wikitext_to_json.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/bots/sledrun_wikitext_to_json.py b/bots/sledrun_wikitext_to_json.py index 428316f..90cdc49 100644 --- a/bots/sledrun_wikitext_to_json.py +++ b/bots/sledrun_wikitext_to_json.py @@ -42,12 +42,6 @@ from pywikibot.site import Namespace docuReplacements = {'¶ms;': pagegenerators.parameterHelp} -def str_or_none(value: Any) -> Optional[str]: - if value is not None: - return str(value) - return None - - def template_to_json(value: Template) -> dict: parameter = [] for p in value.params: @@ -60,9 +54,8 @@ def template_to_json(value: Template) -> dict: def wikilink_to_json(value: Wikilink) -> dict: wl = {'title': str(value.title)} - text = str_or_none(value.text) - if text is not None: - wl['text'] = text + if value.text is not None: + wl['text'] = str(value.text) return wl @@ -274,8 +267,8 @@ class SledrunWikiTextToJsonBot( z = node.get(2, None) if z is not None: ya['name_local'] = str(z) - za = str_or_none(node.get(3, None)) - zb = str_or_none(node.get(4, None)) + za = str(node.get(3, '')).strip() + zb = str(node.get(4, '')).strip() z = lonlat_ele_to_json(opt_lonlat_from_str(za), opt_uint_from_str(zb)) if len(z) > 0: ya['position'] = z @@ -319,8 +312,8 @@ class SledrunWikiTextToJsonBot( x = [] for w in v.ifilter_templates(matches='Parkplatz'): - za = str_or_none(w.get(1, None)) - zb = str_or_none(w.get(2, None)) + za = str(w.get(1, '')).strip() + zb = str(w.get(2, '')).strip() z = lonlat_ele_to_json(opt_lonlat_from_str(za), opt_uint_from_str(zb)) if len(z) > 0: x.append({'position': z}) -- 2.39.5