[ckan-dev] Feature Request: Upserts in ckanclient
Friedrich Lindenberg
friedrich.lindenberg at okfn.org
Wed Sep 21 20:10:48 UTC 2011
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)
- Friedrich
--
Open Knowledge Foundation
Promoting Open Knowledge in a Digital Age
http://www.okfn.org/ - http://blog.okfn.org/
http://twitter.com/pudo
http://pudo.org
More information about the ckan-dev
mailing list