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,
25 from wrpylib.wrmwmarkup import create_sledrun_wiki
28 docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
31 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() or sledrun_json_page.content_model != 'json':
43 sledrun_json = json.loads(sledrun_json_page.text)
44 map_json_page = Page(self.site, self.current_page.title() + '/Landkarte.json')
45 if map_json_page.exists():
46 map_json = json.loads(map_json_page.text)
49 text = create_sledrun_wiki(sledrun_json, map_json)
50 summary = 'Rodelbahnbeschreibung von aus JSON Daten aktualisiert.'
51 self.put_current(text, summary=summary)
54 def main(*args: str) -> None:
55 local_args = pywikibot.handle_args(args)
56 gen_factory = pagegenerators.GeneratorFactory()
57 gen_factory.handle_args(local_args)
58 gen = gen_factory.getCombinedGenerator(preload=True)
60 bot = SledrunFromJsonBot(generator=gen)
63 pywikibot.bot.suggest_help(missing_generator=True)
66 if __name__ == '__main__':