|
| 1 | +#!/usr/bin/python3 |
| 2 | +import json |
| 3 | +import os |
| 4 | +import glob |
| 5 | +import argparse |
| 6 | +from pprint import pprint |
| 7 | +from ckanapi import RemoteCKAN |
| 8 | + |
| 9 | +# http://docs.ckan.org/en/latest/api/index.html#ckan.logic.action.create.resource_create |
| 10 | + |
| 11 | +parser = argparse.ArgumentParser(description='CKAN uploader') |
| 12 | + |
| 13 | +parser.add_argument('-c', '--config', |
| 14 | +# action="store", dest="query", |
| 15 | + help="config file", default="config.json") |
| 16 | + |
| 17 | +args = parser.parse_args() |
| 18 | + |
| 19 | + |
| 20 | +configFilename = args.config |
| 21 | + |
| 22 | +config = json.load(open(configFilename)) |
| 23 | +pprint(config) |
| 24 | +#quit() |
| 25 | +ckanConfig = config['ckan']; |
| 26 | +pprint(ckanConfig) |
| 27 | + |
| 28 | +ckan = RemoteCKAN(ckanConfig['url'], ckanConfig['apiKey'], user_agent=ckanConfig['userAgent']) |
| 29 | + |
| 30 | +#pprint([x for x in os.listdir(".") if x.endswith(".json")]) |
| 31 | +for filename in glob.iglob('**/*.json', recursive=True): |
| 32 | + print(filename) |
| 33 | + |
| 34 | + |
| 35 | +#ua = 'ckanapiexample/1.0 (+http://example.com/my/website)' |
| 36 | + |
| 37 | +print('package update') |
| 38 | +ckan.action.package_update( |
| 39 | + name='my-test-dataset', |
| 40 | + title='this will work fine too') |
| 41 | + |
| 42 | + |
| 43 | +print('resource update') |
| 44 | +ckan.action.resource_create( |
| 45 | + id='my-resource', |
| 46 | + name='my-resource', |
| 47 | + package_id='my-test-dataset', |
| 48 | + url='dummy-value', # ignored but required by CKAN<2.6 |
| 49 | + upload=open('test.csv', 'rb')) |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +#ckan = ckanclient.CkanClient(base_location='http://ckan.qrowd.aksw.org/api', api_key='25b91078-fbc6-4b3a-93c5-acfce414bbeb') |
| 55 | +#ckan.upload_file('testdata.csv') |
| 56 | +#ckan.add_package_resource('mydatasetx', 'testdata.csv', resource_type='data', description='foobar') |
| 57 | + |
| 58 | +#ckan.add_package_resource('my_dataset', 'http://example.org/foo.txt', |
| 59 | +# name='Foo', resource_type='metadata', format='csv') |
| 60 | + |
0 commit comments