Skip to content

Instantly share code, notes, and snippets.

@rufuspollock
Created March 1, 2014 16:49
Show Gist options
  • Save rufuspollock/9292787 to your computer and use it in GitHub Desktop.
Save rufuspollock/9292787 to your computer and use it in GitHub Desktop.
Automated use of CKAN DataPusher from python code
import urlparse
import json
import requests
# set your api key for this work
apikey = 'XXXXX'
datapusher_url = 'http://datapusher-test.herokuapp.com'
ckan_url = 'http://datahub.io'
# gold prices
res_id = 'b9aae52b-b082-4159-b46f-7bb9c158d013'
res = requests.post(
urlparse.urljoin(datapusher_url, 'job'),
headers={
'Content-Type': 'application/json'
},
data=json.dumps({
'api_key': apikey,
'job_type': 'push_to_datastore',
'result_url': '',
'metadata': {
'ckan_url': ckan_url,
'resource_id': res_id,
'set_url_type': False
}
})
)
print res.status_code
print res.json()
data = res.json()
job_url = datapusher_url + '/job/' + data['job_id']
print('curl -H "Authorization: %s" %s' % (data['job_key'], job_url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment