]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Further work on parsing (now a map is parsed).
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 29 Nov 2021 22:12:02 +0000 (23:12 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Mon, 29 Nov 2021 22:41:43 +0000 (23:41 +0100)
bots/sledrun_wikitext_to_json.py

index 686a196c5897de9a14cd39aa0c37654ab2e90c2c..c770e92483fdda5b15a2317411072e18310b9fa6 100644 (file)
@@ -24,9 +24,9 @@ from pywikibot.bot import (
 from pywikibot.logging import warning
 from pywikibot.site._namespace import BuiltinNamespace
 
-from wrpylib.wrmwmarkup import create_sledrun_wiki, lonlat_to_json, lonlat_ele_to_json
+from wrpylib.wrmwmarkup import create_sledrun_wiki, lonlat_to_json, lonlat_ele_to_json, parse_wrmap
 from wrpylib.wrvalidators import rodelbahnbox_from_template, tristate_german_to_str, difficulty_german_to_str, \
-    avalanches_german_to_str, public_transport_german_to_str
+    avalanches_german_to_str, public_transport_german_to_str, opt_str_opt_comment_enum_to_str
 
 from pywikibot.site import Namespace
 
@@ -65,6 +65,11 @@ class SledrunWikiTextToJsonBot(
             warning(f"{map_json_page.title()} already exists, skipping {self.current_page.title()}.")
             return
 
+        map_json = None
+        v = wikicode.filter_tags(matches='wrmap')
+        if len(v) > 0:
+            map_json = parse_wrmap(str(v[0]))
+
         sledrun_json = {
             "name": self.current_page.title(),
             "aliases": [],
@@ -72,7 +77,6 @@ class SledrunWikiTextToJsonBot(
             "description": "Holadrio!",
         }
 
-        map_json = None
 
         rbb_list = wikicode.filter_templates(recursive=False, matches=lambda t: t.name.strip() == 'Rodelbahnbox')
         if len(rbb_list) == 1:
@@ -122,6 +126,11 @@ class SledrunWikiTextToJsonBot(
             if w is not None:
                 sledrun_json['nightlight_description'] = w
 
+            v = rbb['Rodelverleih']
+            if v is not None:
+                sledrun_json['sled_rental_direct'] = v != []
+                sledrun_json['sled_rental_description'] = opt_str_opt_comment_enum_to_str(v)
+
             v = rbb['In Übersichtskarte']
             if v is not None:
                 sledrun_json['show_in_overview'] = v
@@ -142,6 +151,10 @@ class SledrunWikiTextToJsonBot(
             if v != {}:
                 sledrun_json['bottom'] = v
 
+            v = rbb['Telefonauskunft']
+            if v is not None:
+                sledrun_json['info_phone'] = [{'phone': p, 'name': n} for p, n in v]
+
             v = rbb['Öffentliche Anreise']
             if v is not None:
                 sledrun_json['public_transport'] = public_transport_german_to_str(v)