0f1251c May 26, 2017
1 contributor

Users who have contributed to this file

30 lines (27 sloc) 1021 Bytes
import requests
from pprint import pprint
from tabulator import Stream
from goodtables import Inspector, preset
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'):
'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('', preset='ckan')