]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Fix handling of empty coordinates.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 23 Jan 2022 21:29:57 +0000 (22:29 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 23 Jan 2022 21:29:57 +0000 (22:29 +0100)
bots/sledrun_wikitext_to_json.py

index 428316fdf983f4e69fdd61ab58c0eeb0ccd67895..90cdc49e24c70ec108d7bef1ddc486123c250521 100644 (file)
@@ -42,12 +42,6 @@ from pywikibot.site import Namespace
 docuReplacements = {'&params;': pagegenerators.parameterHelp}
 
 
 docuReplacements = {'&params;': 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:
 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)}
 
 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
 
 
     return wl
 
 
@@ -274,8 +267,8 @@ class SledrunWikiTextToJsonBot(
                         z = node.get(2, None)
                         if z is not None:
                             ya['name_local'] = str(z)
                         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
                         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'):
 
             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})
                 z = lonlat_ele_to_json(opt_lonlat_from_str(za), opt_uint_from_str(zb))
                 if len(z) > 0:
                     x.append({'position': z})