1

I used to query with ckanclient thusly:

import ckanclient
ckan = ckanclient.CkanClient('http://catalog.data.gov/api/3')
search_params = {                                           
    'q': 'tags:"sea_water_temperature" AND metadata_modified:[2012-06-01T00:00:00.000Z TO NOW]',  
    'fq': 'res_format:HTML',                                
    'extras': {"ext_bbox":"-71.5,41.,-63,46.0"},                   
    'rows': 3                                                     
}
d = ckan.action('package_search', **search_params) 
print d['count']search_params = {                                           
    'q': 'tags:"sea_water_temperature" AND metadata_modified:[2012-06-01T00:00:00.000Z TO NOW]',  
    'fq': 'res_format:HTML',                                
    'extras': {"ext_bbox":"-71.5,41.,-63,46.0"},                   
    'rows': 3                                                     
}
d = ckan.action('package_search', **search_params) 
print d['count']

How would I do the same with ckanapi?

This doesn't work:

import ckanapi
ckan = ckanapi.RemoteCKAN('https://data.noaa.gov/api/3')
search_params = {                                           
    'q': 'tags:"sea_water_temperature" AND metadata_modified:[2012-06-01T00:00:00.000Z TO NOW]',  
    'fq': 'res_format:HTML',                                
    'extras': {"ext_bbox":"-71.5,41.,-63,46.0"},                   
    'rows': 3                                                     
}
d = ckan.call_action('package_search', data_dict=search_params) 
print d['count']

Returns a 404 error.

1

Your issue is on line 2 of the "This doesn't work" snippet (the error is including the /api/3). It should be, as follows, in full:

import ckanapi
ckan = ckanapi.RemoteCKAN('https://data.noaa.gov')
search_params = {                                           
    'q': 'tags:"sea_water_temperature" AND metadata_modified:[2012-06-01T00:00:00.000Z TO NOW]',  
    'fq': 'res_format:HTML',                                
    'extras': {"ext_bbox":"-71.5,41.,-63,46.0"},                   
    'rows': 3                                                     
}
d = ckan.call_action('package_search', data_dict=search_params) 
print d['count']

Which prints 29 for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.