Add code for mediawiki compare API
This commit is contained in:
parent
0cc4f3ed7f
commit
16e776c058
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue