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 Edit JSON associated with sledruns.
8 The following generators and filters are supported:
14 from jsonschema import validate
17 from pywikibot import pagegenerators, Page
18 from pywikibot.bot import (
19 AutomaticTWSummaryBot,
26 from wrpylib.json_tools import order_json_keys
28 docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
31 class SledrunFromJsonBot(
36 AutomaticTWSummaryBot,
38 def setup(self) -> None:
39 schema = Page(self.site, 'Winterrodeln:Datenschema/Rodelbahn/V1.json')
40 assert schema.content_model == 'json'
41 self.sledrun_schema = json.loads(schema.text)
43 def treat_page(self) -> None:
44 """Load the given page, do some changes, and save it."""
45 content_json = json.loads(self.current_page.text)
47 validate(instance=content_json, schema=self.sledrun_schema)
49 content_json_ordered = order_json_keys(content_json, self.sledrun_schema)
50 assert content_json_ordered == content_json
51 text = json.dumps(content_json_ordered, ensure_ascii=False, indent=4)
53 except jsonschema.exceptions.ValidationError as e:
56 summary = 'JSON Daten aktualisiert.'
57 self.put_current(text, summary=summary)
60 def main(*args: str) -> None:
61 local_args = pywikibot.handle_args(args)
62 gen_factory = pagegenerators.GeneratorFactory()
63 gen_factory.handle_args(local_args)
64 gen = gen_factory.getCombinedGenerator(preload=True)
66 bot = SledrunFromJsonBot(generator=gen)
69 pywikibot.bot.suggest_help(missing_generator=True)
72 if __name__ == '__main__':