Skip to content

Commit b2a8161

Browse files
committed
initial ckan upload script
1 parent a3446b9 commit b2a8161

6 files changed

+94
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# BlueJ files
88
*.ctxt
99

10+
11+
config.json
12+
13+
1014
# Mobile Tools for Java (J2ME)
1115
.mtj.tmp/
1216

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@ npm install -g gtfs-csv2rdf
1717
## 1020 to 1033
1818

1919
[GeoKnow/TripleGeo: TripleGeo utility for converting geospatial data into triples](https://github.com/GeoKnow/TripleGeo)
20+
21+
22+
23+
## Ckan uploads
24+
This is accomplished using a python script
25+
26+
```bash
27+
sudo apt-get update
28+
sudo apt-get -y install python3-pip
29+
30+
sudo pip3 install rdflib
31+
32+
```
33+

config.json.dist

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ckan": {
3+
"url": "http://ckan.qrowd.aksw.org/",
4+
"apiKey": "secret",
5+
"userAgent": "Your Name <[email protected]>"
6+
}
7+
}

datasets/1046-1051/meta.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"datasets": [{
3+
"id": "time-table",
4+
"cmd": "sparql-integrate workloads.json"
5+
"x": ""
6+
}]
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+

test.csv

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test test test
2+
test test test

0 commit comments

Comments
 (0)