forked from frictionlessdata/frictionless-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckan.py
29 lines (27 loc) · 1021 Bytes
/
ckan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
from pprint import pprint
from tabulator import Stream
from goodtables import Inspector, preset
@preset('ckan')
def ckan_preset(source, **options):
warnings = []
tables = []
url = '%s/api/3/action/package_search' % source
data = requests.get(url).json()
for package in data['result']['results']:
for resource in package['resources']:
if resource['url'].endswith('.csv'):
tables.append({
'source': resource['url'],
'stream': Stream(resource['url'], headers=1),
'schema': None,
'extra': {
'dataset': package['title'],
'resource': resource['name'],
'publisher': package['organization']['name']
},
})
return warnings, tables
inspector = Inspector(custom_presets=[ckan_preset])
report = inspector.inspect('http://data.surrey.ca', preset='ckan')
pprint(report)