Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
__author__ = 'Sebastian Burgstaller'
from PBB_login import WDLogin
import requests
import json
import pprint
user = ''
pwd = ''
# login = WD_Login(user=user, password=pwd)
login_obj = WDLogin(user=user, pwd=pwd, server='test.wikidata.org')
cookies = login_obj.get_edit_cookie()
edit_token = login_obj.get_edit_token()
try:
query = 'https://test.wikidata.org/w/api.php'
token = edit_token
print(token)
data = '{"claims":[{"id": "Q1232$CE803569-5434-4D0B-8A80-E0F04C345FB9","remove": ""}]}'
headers = {'content-type': 'application/x-www-form-urlencoded'}
payload = {'action': 'wbeditentity',
'id': 'Q1232',
'data': data,
'format': 'json',
'token': token}
print(query)
# reply = json.load(urllib2.urlopen(query))
reply = requests.post(query, headers=headers, data=payload, cookies=cookies)
json_data = json.loads(reply.text)
pprint.pprint(json_data)
except requests.HTTPError as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment