"""
import json
+import mwparserfromhell
import pywikibot
from pywikibot import pagegenerators, Page
from pywikibot.bot import (
SingleSiteBot,
)
from pywikibot.logging import warning
+from pywikibot.site._namespace import BuiltinNamespace
-from wrpylib.wrmwmarkup import create_sledrun_wiki
+from wrpylib.wrmwmarkup import create_sledrun_wiki, lonlat_to_json, lonlat_ele_to_json
+from wrpylib.wrvalidators import rodelbahnbox_from_template, tristate_german_to_str, difficulty_german_to_str, \
+ avalanches_german_to_str, public_transport_german_to_str
+from pywikibot.site import Namespace
docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
f"instead of {wikitext_content_model}.")
return
+ wikicode = mwparserfromhell.parse(self.current_page.text)
+ wikilink_list = wikicode.filter_wikilinks()
+ category_sledrun = 'Kategorie:Rodelbahn'
+ if sum(1 for c in wikilink_list if c.title == category_sledrun) == 0:
+ warning(f'The page {self.current_page.title()} does not have category {category_sledrun}.')
+ return
+
sledrun_json_page = Page(self.site, self.current_page.title() + '/Rodelbahn.json')
if sledrun_json_page.exists():
warning(f"{sledrun_json_page.title()} already exists, skipping {self.current_page.title()}.")
sledrun_json = {
"name": self.current_page.title(),
+ "aliases": [],
+ "entry_under_construction": sum(1 for c in wikilink_list if c.text == 'Kategorie:In Arbeit') > 0,
"description": "Holadrio!",
}
map_json = None
+ rbb_list = wikicode.filter_templates(recursive=False, matches=lambda t: t.name.strip() == 'Rodelbahnbox')
+ if len(rbb_list) == 1:
+ rbb = rodelbahnbox_from_template(rbb_list[0])
+ v = rbb['Bild']
+ if v is not None:
+ image_page = Page(self.site, v, ns=BuiltinNamespace.FILE)
+ if image_page.exists():
+ warning(f"{image_page.title()} does not exist.")
+ sledrun_json['image'] = v
+
+ v = rbb['Länge']
+ if v is not None:
+ sledrun_json['length'] = v
+
+ v = rbb['Schwierigkeit']
+ if v is not None:
+ sledrun_json['difficulty'] = difficulty_german_to_str(v)
+
+ v = rbb['Lawinen']
+ if v is not None:
+ sledrun_json['avalanches'] = avalanches_german_to_str(v)
+
+ v, w = rbb['Betreiber']
+ if v is not None:
+ sledrun_json['has_operator'] = v
+ if w is not None:
+ sledrun_json['operator'] = w
+
+ v = rbb['Aufstieg möglich']
+ if v is not None:
+ sledrun_json['walkup_possible'] = v
+
+ v, w = rbb['Aufstieg getrennt']
+ if v is not None:
+ sledrun_json['walkup_separate'] = tristate_german_to_str(v)
+ if w is not None:
+ sledrun_json['walkup_comment'] = w # TODO
+
+ v = rbb['Gehzeit']
+ if v is not None:
+ sledrun_json['walkup_time'] = v
+
+ v, w = rbb['Beleuchtungsanlage']
+ if v is not None:
+ sledrun_json['nightlight_possible'] = tristate_german_to_str(v)
+ if w is not None:
+ sledrun_json['nightlight_description'] = w
+
+ v = rbb['In Übersichtskarte']
+ if v is not None:
+ sledrun_json['show_in_overview'] = v
+
+ v = rbb['Forumid']
+ if v is not None:
+ sledrun_json['forum_id'] = v
+
+ v = rbb['Position']
+ if v is not None:
+ sledrun_json['position'] = lonlat_to_json(v)
+
+ v = lonlat_ele_to_json(rbb['Position oben'], rbb['Höhe oben'])
+ if v != {}:
+ sledrun_json['top'] = v
+
+ v = lonlat_ele_to_json(rbb['Position unten'], rbb['Höhe unten'])
+ if v != {}:
+ sledrun_json['bottom'] = v
+
+ v = rbb['Öffentliche Anreise']
+ if v is not None:
+ sledrun_json['public_transport'] = public_transport_german_to_str(v)
+
text = create_sledrun_wiki(sledrun_json, map_json)
summary = 'Rodelbahnbeschreibung nach Konvertierung nach und von JSON.'
self.put_current(text, summary=summary)