]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Parse car_distances.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 12 Dec 2021 15:59:19 +0000 (16:59 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Sun, 12 Dec 2021 15:59:19 +0000 (16:59 +0100)
bots/sledrun_wikitext_to_json.py

index 8827f2bd1f8a87f6069d7f29ff303281ff36a77b..966604cbe532fc269409ae8dda91fadbc149a1f4 100644 (file)
@@ -9,7 +9,9 @@ The following generators and filters are supported:
 
 &params;
 """
+import io
 import json
+import re
 from typing import Any, Optional
 
 import mwparserfromhell
@@ -251,6 +253,20 @@ class SledrunWikiTextToJsonBot(
                 if len(x) > 0:
                     sledrun_json['car_parking'] = x
 
+                x = []
+                for w in io.StringIO(str(v)):
+                    match = re.match(r"\*\* von \'\'\'(.+)\'\'\'(.*): ([\d.,]+) km", w.rstrip())
+                    if match:
+                        ya, yb, yc = match.groups()
+
+                        yc = float(yc.replace(',', '.'))
+                        x.append({
+                            'km': yc,
+                            'route': (ya.strip() + ' ' + yb.strip()).strip(),
+                        })
+                if len(x) > 0:
+                    sledrun_json['car_distances'] = x
+
             x = []
             for v in wikicode.get_sections(levels=[2], matches='Allgemeines'):
                 i = iter(v.nodes)