Skip to content

Instantly share code, notes, and snippets.

@sebotic
Created June 29, 2015 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebotic/d372a84f8987e25a29a7 to your computer and use it in GitHub Desktop.
Save sebotic/d372a84f8987e25a29a7 to your computer and use it in GitHub Desktop.
__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