]> ToastFreeware Gitweb - philipp/winterrodeln/wrpylib.git/blobdiff - scripts/update_sledrun_wikitext.py
Implement parameter "all".
[philipp/winterrodeln/wrpylib.git] / scripts / update_sledrun_wikitext.py
index cd8fe36fc9a8b1f968885b5e190e4dbe68265fb7..075dd8875495324cb5b8ee4aba8931cfe4fc603c 100644 (file)
@@ -1,12 +1,13 @@
 #!/usr/bin/python
 import argparse
 import json
+import sys
 from typing import List
 
+from termcolor import cprint  # python3-termcolor
 import jsonschema
-import pywikibot
-from pywikibot import input_yn
 
+from wrpylib.cli_tools import unified_diff, input_yes_no_quit, Choice
 from wrpylib.mwapi import WikiSite
 from wrpylib.wrmwmarkup import create_sledrun_wiki
 
@@ -35,11 +36,15 @@ def update_sledrun(site: WikiSite, wiki_page: dict, json_page: dict, map_page: d
     if new_text == previous_text:
         return
 
-    pywikibot.showDiff(previous_text.strip(), new_text.strip(), context=2)
-    yn = input_yn('Do you accept the changes?', True)
-    if not yn:
+    cprint(wiki_page['title'], 'green')
+    unified_diff(previous_text, new_text)
+    choice = input_yes_no_quit('Do you accept the changes [yes, no, quit]? ', None)
+    if choice == Choice.no:
         return
 
+    if choice == Choice.quit:
+        sys.exit(0)
+
     site(
         'edit',
         pageid=wiki_page['pageid'],
@@ -69,7 +74,7 @@ def update_sledrun_wikitext(ini_files: List[str], update_all: bool):
             assert wikitext_page['title'] + '/Rodelbahn.json' == json_page['title']
             if 'missing' in json_page:
                 continue
-            if wikitext_page['revisions'][0]['timestamp'] < json_page['revisions'][0]['timestamp']:
+            if update_all or (wikitext_page['revisions'][0]['timestamp'] < json_page['revisions'][0]['timestamp']):
                 update_wikitext_title_list.append(wikitext_page['title'])
                 update_json_title_list.append(json_page['title'])