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.

2 Answers 2

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.

1

For some reason, the above solution has not worked for me. I tried data.gov catalog and used the same code as below:

import ckanapi ckan = ckanapi.RemoteCKAN('https://catalog.data.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'])

prints 212284

Changing search parameters to something weird that theoritically should fetch zero record, also brings 212284 as an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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