Created
May 16, 2012 14:36
-
-
Save amercader/2710833 to your computer and use it in GitHub Desktop.
Quick and dirty CKAN to CKAN import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
ORI_SERVER = 'http://thedatahub.org' | |
DEST_SERVER = 'http://demo.ckan.org' | |
API_KEY = '<YOUR_API_KEY>' | |
#NAMES = ['gold-prices'] #This one failed (?) | |
NAMES = [ | |
'afterfibre', | |
'us-national-foreclosure-statistics-january-2012', | |
'malawi-aid-projects', | |
'italyregionalaccounts', | |
'adur_district_spending', | |
'newcastle-city-council-payments-over-500', | |
'afghanistan-election-data' | |
] | |
headers = { | |
'Authorization':API_KEY | |
} | |
base_url_ori = '%s/api/rest/dataset' % ORI_SERVER | |
base_url_dest = '%s/api/rest/dataset' % DEST_SERVER | |
for name in NAMES: | |
url_ori = '%s/%s' % (base_url_ori,name) | |
pkg_dict = json.loads(requests.get(url_ori).content) | |
del pkg_dict['id'] | |
del pkg_dict['groups'] | |
res = requests.post(base_url_dest,headers=headers,data=json.dumps(pkg_dict)) | |
print 'Imported dataset %s [%s]' % (name,res.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment