Add 'get history' mediawiki API call
This commit is contained in:
parent
3e445a3133
commit
cacafb1d52
|
@ -24,8 +24,10 @@ def api_call(params, api_url=wikidata_url):
|
||||||
r = requests.get(api_url, params=call_params, timeout=5)
|
r = requests.get(api_url, params=call_params, timeout=5)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def get_entity(qid):
|
def get_entity(qid, redirects=False):
|
||||||
json_data = api_call({'action': 'wbgetentities', 'ids': qid}).json()
|
json_data = api_call({'action': 'wbgetentities',
|
||||||
|
'ids': qid,
|
||||||
|
'redirects': {True: 'yes', False: 'no'}[redirects]}).json()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
entity = list(json_data['entities'].values())[0]
|
entity = list(json_data['entities'].values())[0]
|
||||||
|
@ -162,3 +164,12 @@ def get_categories(titles, site):
|
||||||
continue
|
continue
|
||||||
title_and_cats.append((i['title'], cats))
|
title_and_cats.append((i['title'], cats))
|
||||||
return title_and_cats
|
return title_and_cats
|
||||||
|
|
||||||
|
def get_history(title, site):
|
||||||
|
params = {
|
||||||
|
'prop': 'revisions',
|
||||||
|
'rvlimit': 'max',
|
||||||
|
'rvprop': 'timestamp|user|comment|ids|content',
|
||||||
|
'rvslots': 'main',
|
||||||
|
}
|
||||||
|
return mediawiki_query([title], params, site)
|
||||||
|
|
Loading…
Reference in a new issue