3 User script for pywikibot (https://gerrit.wikimedia.org/r/pywikibot/core.git), tested with version 6.6.1.
4 Put it in directory scripts/userscripts.
6 Replace a sledrun page with content generated from associated JSON subpages
7 (Rodelbahn and Landkarte).
9 The following generators and filters are supported:
16 from pywikibot import pagegenerators, Page
17 from pywikibot.bot import (
18 AutomaticTWSummaryBot,
24 from pywikibot.logging import warning
26 from wrpylib.wrmwmarkup import create_sledrun_wiki
29 docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
32 class SledrunFromJsonBot(
36 AutomaticTWSummaryBot,
38 def treat_page(self) -> None:
39 """Load the given page, do some changes, and save it."""
40 sledrun_json_page = Page(self.site, self.current_page.title() + '/Rodelbahn.json')
41 if not sledrun_json_page.exists():
42 warning(f"{sledrun_json_page.title()} does not exist. Skipping.")
44 if sledrun_json_page.content_model != 'json':
45 warning(f"Content model of {sledrun_json_page.title()} is not 'json'.")
47 sledrun_json = json.loads(sledrun_json_page.text)
48 map_json_page = Page(self.site, self.current_page.title() + '/Landkarte.json')
49 if map_json_page.exists():
50 map_json = json.loads(map_json_page.text)
54 sledrun_impressions_page = Page(self.site, self.current_page.title() + '/Impressionen')
55 if sledrun_impressions_page.exists():
56 impressions = sledrun_impressions_page.title()
57 text = create_sledrun_wiki(sledrun_json, map_json, impressions)
58 summary = 'Rodelbahnbeschreibung aus JSON Daten aktualisiert.'
59 pywikibot.showDiff(self.current_page.text.strip(), text.strip(), context=2)
60 self.put_current(text, summary=summary, show_diff=False)
63 def main(*args: str) -> None:
64 local_args = pywikibot.handle_args(args)
65 gen_factory = pagegenerators.GeneratorFactory()
66 gen_factory.handle_args(local_args)
67 gen = gen_factory.getCombinedGenerator(preload=True)
69 bot = SledrunFromJsonBot(generator=gen)
72 pywikibot.bot.suggest_help(missing_generator=True)
75 if __name__ == '__main__':