[ckan-dev] Feature Request: Upserts in ckanclient
Rufus Pollock
rufus.pollock at okfn.org
Thu Sep 22 22:38:51 UTC 2011
On 21 September 2011 21:10, Friedrich Lindenberg
<friedrich.lindenberg at okfn.org> wrote:
> Hi all,
>
> I'm working on one of the community instances and essentially I'm
> writing some scraper scripts to pipe packages into CKAN.
> Micro-harvesters, in a sense. What I'd really like would be upsert
> functions like this:
>
> def client():
> return CkanClient(base_location=CKAN_URL + '/api', api_key=CKAN_KEY)
>
> def upsert_group(data):
> name = data['name']
> c = client()
> try:
> grp = c.group_entity_get(name)
> grp = c.group_entity_put(data)
> except CkanApiNotFoundError:
> #print "Create %s" % name
> grp = c.group_register_post(data)
> return grp
>
> def upsert_package(data):
> name = data['name']
> c = client()
> try:
> pkg = c.package_entity_get(name)
> pkg = c.package_entity_put(data)
> except CkanApiNotFoundError:
> #print "Create %s" % name
> pkg = c.package_register_post(data)
> return pkg
>
> def add_package_to_group(group_name, pkg_name):
> c = client()
> grp = c.group_entity_get(group_name)
> grp['packages'].append(pkg_name)
> return c.group_entity_put(grp)
sounds like a good patch :-) Do you want to fork, apply and then we
merge to ckanclient?
Rufus
More information about the ckan-dev
mailing list