Add code for mediawiki compare API

This commit is contained in:
Edward Betts 2022-08-21 11:30:02 +01:00
parent 0cc4f3ed7f
commit 16e776c058
2 changed files with 15 additions and 0 deletions

View file

@ -43,3 +43,18 @@ def get_content(title: str) -> str:
data = call(params) data = call(params)
rev: str = data["query"]["pages"][0]["revisions"][0]["content"] rev: str = data["query"]["pages"][0]["revisions"][0]["content"]
return rev 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