]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/commitdiff
Add "see also".
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 10 Dec 2021 20:37:34 +0000 (21:37 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Fri, 10 Dec 2021 20:37:34 +0000 (21:37 +0100)
bots/sledrun_wikitext_to_json.py

index b7ba7a70e18b5f3d256455bf4d0952a82df818ff..4bc22162fc900fc155d46e315142b5da6a6af985 100644 (file)
@@ -13,6 +13,7 @@ import json
 
 import mwparserfromhell
 import pywikibot
+from mwparserfromhell.nodes import Tag, Text, ExternalLink
 from pywikibot import pagegenerators, Page
 from pywikibot.bot import (
     AutomaticTWSummaryBot,
@@ -165,6 +166,31 @@ class SledrunWikiTextToJsonBot(
             if v is not None:
                 sledrun_json['public_transport'] = public_transport_german_to_str(v)
 
+            x = []
+            for v in wikicode.get_sections(levels=[2], matches='Allgemeines'):
+                i = iter(v.nodes)
+                w = next(i, None)
+                while w is not None:
+                    if isinstance(w, Tag) and str(w) == "'''Siehe auch'''":
+                        w = next(i, None)
+                        break
+                    w = next(i, None)
+                while w is not None:
+                    if isinstance(w, ExternalLink):
+                        link = {'url': w.url}
+                        if w.title is not None:
+                            link['text'] = w.title
+                        x.append(link)
+                    elif isinstance(w, (Text, Tag)) and str(w).strip() in ['', '*', ':']:
+                        pass
+                    else:
+                        break
+                    w = next(i, None)
+            if len(x) > 0:
+                sledrun_json['see_also'] = x
+
+            sledrun_json['allow_reports'] = True
+
         text = create_sledrun_wiki(sledrun_json, map_json)
         summary = 'Rodelbahnbeschreibung nach Konvertierung nach und von JSON.'
         self.put_current(text, summary=summary)