From: Philipp Spitzer Date: Fri, 10 Dec 2021 20:37:34 +0000 (+0100) Subject: Add "see also". X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/wrpylib.git/commitdiff_plain/6c364e1e2cafee11f1ac5c8006b2e2310fbe316f Add "see also". --- diff --git a/bots/sledrun_wikitext_to_json.py b/bots/sledrun_wikitext_to_json.py index b7ba7a7..4bc2216 100644 --- a/bots/sledrun_wikitext_to_json.py +++ b/bots/sledrun_wikitext_to_json.py @@ -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)