Skip to content

Instantly share code, notes, and snippets.

@frankstrater
Created October 11, 2021 07:20
Show Gist options
  • Save frankstrater/130a5308f8df9e0493f5dbae72a9bd11 to your computer and use it in GitHub Desktop.
Save frankstrater/130a5308f8df9e0493f5dbae72a9bd11 to your computer and use it in GitHub Desktop.
CKAN get datasets tests
#!/usr/bin/python3
import requests
import json
api_url = 'https://mediasuitedata.clariah.nl/api'
cacheFile = 'ckan_test.json'
response = requests.get(api_url + '/action/package_list')
listCKANCollections = response.json()['result']
collectionData = {}
for collectionId in listCKANCollections:
response = requests.get(api_url + '/action/package_show?id=' + collectionId)
collectionData[collectionId] = response.json()['result']
f = open(cacheFile, 'w+')
prettyData = json.dumps(collectionData, indent=4, sort_keys=True)
f.write(prettyData)
f.close()
#!/usr/bin/python3
import requests
import json
api_url = 'https://mediasuitedata.clariah.nl/api'
cacheFile = 'ckan_test_new.json'
response = requests.get(api_url + '/action/current_package_list_with_resources?limit=1000')
listCKANCollections = response.json()['result']
collectionData = {}
for collection in listCKANCollections:
collectionId = collection['name']
collectionData[collectionId] = collection
f = open(cacheFile, 'w+')
prettyData = json.dumps(collectionData, indent=4, sort_keys=True)
f.write(prettyData)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment