User:Adarshpatel509/Sandbox/Compare

From mediawiki.org

Compare two revisions from the same page


Sample code[edit]

compare_page_revisions.py

#!/usr/bin/python3

"""
    compare_page_revisions.py

    MediaWiki Action API Code Samples
    Demo of `Compare` module: Compare two revisions from the same page
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "compare",
    "format": "json",
    "fromrev": "139992",
    "torev": "139993"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)


Compare the current revisions of two different pages


Sample code[edit]

compare_pages.py

#!/usr/bin/python3

"""
    compare_pages.py

    MediaWiki Action API Code Samples
    Demo of `Compare` module: Compare the current revisions of two different pages
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "compare",
    "format": "json",
    "fromtitle": "Template:Unsigned",
    "totitle": "Template:UnsignedIP"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)


Compare a revision of a page to some text


Sample code[edit]

compare_page_with_text.py

#!/usr/bin/python3

"""
    compare_page_with_text.py

    MediaWiki Action API Code Samples
    Demo of `Compare` module: Compare a revision of a page to some text
    MIT License
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    "action": "compare",
    "format": "json",
    "fromrev": "829678781",
    "totext": "test%20edit,%20please%20ignore"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)