"""
import json
+import jsonschema
import pywikibot
from jsonschema import validate
-from pywikibot import pagegenerators, Page
+from pywikibot import pagegenerators, Page, warning
from pywikibot.bot import (
AutomaticTWSummaryBot,
ConfigParserBot,
from wrpylib.json_tools import order_json_keys
from wrpylib.wrmwmarkup import create_sledrun_wiki
-
docuReplacements = {'¶ms;': pagegenerators.parameterHelp}
def treat_page(self) -> None:
"""Load the given page, do some changes, and save it."""
- if self.current_page.content_model != 'json':
+ if self.current_page.content_model != 'wikitext':
+ warning(f"The content model of {self.current_page.title()} is {self.current_page.content_model} "
+ f"instead of wikitext")
+ return
+
+ sledrun_json_page = Page(self.site, self.current_page.title() + '/Rodelbahn.json')
+ if not sledrun_json_page.exists():
+ warning(f"{sledrun_json_page} does not exist.")
return
- content_json = json.loads(self.current_page.text)
- # *here*, content_json can be processed
- processed_json = content_json
+ if sledrun_json_page.content_model != 'json':
+ warning(f"The content model of {sledrun_json_page} is {sledrun_json_page.content_model} "
+ f"instead of json")
+ return
+
+ sledrun_json = json.loads(sledrun_json_page.text)
+ sledrun_json_orig = json.loads(sledrun_json_page.text)
+ sledrun_json_orig_text = json.dumps(sledrun_json_orig, ensure_ascii=False, indent=4)
- validate(instance=processed_json, schema=self.sledrun_schema)
- processed_json_ordered = order_json_keys(processed_json, self.sledrun_schema)
- assert processed_json_ordered == processed_json
- text = json.dumps(processed_json_ordered, ensure_ascii=False, indent=4)
+ # *here*, sledrun_json can be processed
+ jsonschema.validate(instance=sledrun_json, schema=self.sledrun_schema)
+ sledrun_json_ordered = order_json_keys(sledrun_json, self.sledrun_schema)
+ assert sledrun_json_ordered == sledrun_json
+ if sledrun_json == sledrun_json_orig:
+ return
+ sledrun_json_text = json.dumps(sledrun_json_ordered, ensure_ascii=False, indent=4)
summary = 'JSON Daten aktualisiert.'
- self.put_current(text, summary=summary)
+ self.userPut(sledrun_json_page, sledrun_json_orig_text, sledrun_json_text, summary=summary, contentmodel='json')
def main(*args: str) -> None: