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 Create a sledrun JSON page from a sledrun wikitext page (including map).
8 The following generators and filters are supported:
15 from pywikibot import pagegenerators, Page
16 from pywikibot.bot import (
17 AutomaticTWSummaryBot,
23 from pywikibot.logging import warning
25 from wrpylib.wrmwmarkup import create_sledrun_wiki
28 docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
31 class SledrunWikiTextToJsonBot(
36 AutomaticTWSummaryBot,
38 def treat_page(self) -> None:
39 """Load the given page, do some changes, and save it."""
40 wikitext_content_model = 'wikitext'
41 if self.current_page.content_model != wikitext_content_model:
42 warning(f"The content model of {self.current_page.title()} is {self.current_page.content_model} "
43 f"instead of {wikitext_content_model}.")
46 sledrun_json_page = Page(self.site, self.current_page.title() + '/Rodelbahn.json')
47 if sledrun_json_page.exists():
48 warning(f"{sledrun_json_page.title()} already exists, skipping {self.current_page.title()}.")
51 map_json_page = Page(self.site, self.current_page.title() + '/Landkarte.json')
52 if map_json_page.exists():
53 warning(f"{map_json_page.title()} already exists, skipping {self.current_page.title()}.")
57 "name": self.current_page.title(),
58 "description": "Holadrio!",
63 text = create_sledrun_wiki(sledrun_json, map_json)
64 summary = 'Rodelbahnbeschreibung nach Konvertierung nach und von JSON.'
65 self.put_current(text, summary=summary)
68 def main(*args: str) -> None:
69 local_args = pywikibot.handle_args(args)
70 gen_factory = pagegenerators.GeneratorFactory()
71 gen_factory.handle_args(local_args)
72 gen = gen_factory.getCombinedGenerator(preload=True)
74 bot = SledrunWikiTextToJsonBot(generator=gen)
77 pywikibot.bot.suggest_help(missing_generator=True)
80 if __name__ == '__main__':