From 16e776c058fef09c082569ce4516505415ca0b40 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 21 Aug 2022 11:30:02 +0100 Subject: [PATCH] Add code for mediawiki compare API --- dab_mechanic/mediawiki_api.py | 15 +++++++++++++++ templates/{save.html => preview.html} | 0 2 files changed, 15 insertions(+) rename templates/{save.html => preview.html} (100%) diff --git a/dab_mechanic/mediawiki_api.py b/dab_mechanic/mediawiki_api.py index 26d7a20..f681af3 100644 --- a/dab_mechanic/mediawiki_api.py +++ b/dab_mechanic/mediawiki_api.py @@ -43,3 +43,18 @@ def get_content(title: str) -> str: data = call(params) rev: str = data["query"]["pages"][0]["revisions"][0]["content"] return rev + + +def compare(title: str, new_text: str) -> str: + """Generate a diff for the new article text.""" + params: dict[str, str | int] = { + "format": "json", + "formatversion": 2, + "action": "compare", + "fromtitle": title, + "toslots": "main", + "totext-main": new_text, + "prop": "diff", + } + diff: str = call(params)["compare"]["body"] + return diff diff --git a/templates/save.html b/templates/preview.html similarity index 100% rename from templates/save.html rename to templates/preview.html