[ckan-dev] Getting resources from packages via the ckanapi

Ian Ward ian at excess.org
Thu Feb 23 20:29:20 UTC 2017


On Thu, Feb 23, 2017 at 3:14 PM, Koebrick, Andrew (MNIT) <
andrew.koebrick at state.mn.us> wrote:

> Tim,
>
>
>
> I had tried that approach earlier with this syntax which seems to match
> what works for the organization_show:
>
> packageObj = ckan.action.package_show(id=package[*'id'*])
>
> But when I attempt to see what I retrieved like so:
>
> pprint (packageObj)
>
> All that I get is
>
> -1
>

Oh.

Try pprint dict(packageObj)

That -1 repr is due to an old performance hack (when using the actions
internally you're getting a LazyJSON object instead of a normal dict) We've
since reverted that hack. You wouldn't see it if you were using RemoteCKAN
or a newer version of CKAN.

Ian


>
> I thought perhaps it was a problem with my install of ckanapi so I
> upgraded from 3.6 to 4.0 but that did not fix the issue.
>
>
>
> The syntax you suggested seems to have a problem but I also tried this
> variation:
>
> packageObj = ckan.action.package_show(‘*id:' +* package[*'id'*]) #note addition of plus sign…
>
>
>
> which throws:
>
> TypeError: action() takes exactly 0 arguments (1 given)
>
>
>
> Still plunking away…
>
>
>
> Andrew
>
>
>
> *From:* ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] *On Behalf Of *Timothy
> Giles
> *Sent:* Thursday, February 23, 2017 1:21 PM
> *To:* CKAN Development Discussions <ckan-dev at lists.okfn.org>
> *Subject:* Re: [ckan-dev] Getting resources from packages via the ckanapi
>
>
>
> Hi Andrew,
>
>
>
> Once you have the package id, you can :
>
>
>
>                  packageObj = ckan.action.package_show(‘*id:'* package[*'id'*])
>
>
>
> This will return you the package object with all the resources included. You can loop through the resources if you want but I believe all the resource metadata is provided.
>
>
>
> Regards Tim
>
>
>
>
>
> *From:* ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org
> <ckan-dev-bounces at lists.okfn.org>] *On Behalf Of *Koebrick, Andrew (MNIT)
> *Sent:* den 23 februari 2017 19:44
> *To:* ckan-dev at lists.okfn.org
> *Subject:* [ckan-dev] Getting resources from packages via the ckanapi
>
>
>
> Hoping somebody can assist:  I am attempting to create a report for one of
> my ckan instances that lists all the organizations, and then all of their
> packages along with the id of the packages’ resource (we have only one
> resource per package).  However, I do not seem to be able to link to the
> resource id via API calls.
>
>
>
> Here is what I have so far:
>
>
> organizations = ckan.action.organization_list(include_datasets =*'True'*)
> *for *organization *in *organizations:
>
>          packages= orgDetails[*'packages'*]
>
> *         for *package *in *packages:
>
>                  #And here is where it breaks down…. Here are a few of the many searches / shows I have tried:
>
>                  resourceObj = ckan.action.resource_search(query=*'package_id:'* +package[*'id'*])
>
>                     #which returns: {u'query': u'Field "package_id" not recognised in resource_search.', u'__type': u'Validation Error'}
>
>                  revisionObj = ckan.action.revision_show(id=package[*'revision_id'*])
>
>                     #which just brings back information already knows about the revision.
>
>
>
>
>
> While iterating through the package information I seem unable to get the related resources.  I have tried all sorts of queries using what info I have from the package to get the related resources.
>
>
>
> What can I use to link from the package list found in the return object from organization_show to get resources?
>
>
>
> Many thanks,
>
>
>
> *Andrew Koebrick  | * MINNESOTA GEOSPATIAL INFORMATION OFFICE
>
> Web Coordinator / Systems administrator / Librarian
>
> MN.IT Services @ MNGEO
>
> 651-201-2465 <(651)%20201-2465> (w)  *|  * 651-296-6398 <(651)%20296-6398>
> (f) *|*  andrew.koebrick at state.mn.us
>
> 658 Cedar St., Room 300, St. Paul, MN 55155, www.mngeo.state.mn.us
>
> *[image: cid:image002.jpg at 01CE61F8.52552AE0]* <http://www.mn.gov/oet>
>
> Information Technology for Minnesota Government   *|*   mn.gov/mnit
> <http://www.mn.gov/oet>
>
>
>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170223/89629734/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 1624 bytes
Desc: not available
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170223/89629734/attachment-0003.jpg>


More information about the ckan-dev mailing list