#!/usr/bin/python """ User script for pywikibot (https://gerrit.wikimedia.org/r/pywikibot/core.git), tested with version 6.6.1. Put it in directory scripts/userscripts. Edit JSON associated with sledruns. The following generators and filters are supported: ¶ms; """ import json import pywikibot from pywikibot import pagegenerators, Page from pywikibot.bot import ( AutomaticTWSummaryBot, ConfigParserBot, ExistingPageBot, NoRedirectPageBot, SingleSiteBot, ) from wrpylib.wrmwmarkup import create_sledrun_wiki docuReplacements = {'¶ms;': pagegenerators.parameterHelp} class SledrunFromJsonBot( SingleSiteBot, ConfigParserBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot, ): def treat_page(self) -> None: """Load the given page, do some changes, and save it.""" if self.current_page.content_model != 'json': return content_json = json.loads(self.current_page.text) processed_json = content_json text = json.dumps(processed_json, ensure_ascii=False, indent=4) summary = 'JSON Daten aktualisiert.' self.put_current(text, summary=summary) def main(*args: str) -> None: local_args = pywikibot.handle_args(args) gen_factory = pagegenerators.GeneratorFactory() gen_factory.handle_args(local_args) gen = gen_factory.getCombinedGenerator(preload=True) if gen: bot = SledrunFromJsonBot(generator=gen) bot.run() else: pywikibot.bot.suggest_help(missing_generator=True) if __name__ == '__main__': main()