[ckan-dev] Feature Request: Upserts in ckanclient

Rufus Pollock rufus.pollock at okfn.org
Sat Sep 24 12:38:32 UTC 2011


On 23 September 2011 14:09, Friedrich Lindenberg
<friedrich.lindenberg at okfn.org> wrote:
> Hrm, I knew this would come back ;-)
>
> https://bitbucket.org/okfn/ckanclient/pull-request/1/upsert-functions

Looks great but to apply we should probably really have a test :-)

I know it is an ultra-simple patch so I guess we could apply without a
test but I think it is good practice to have one :-)

Rufus

> - Friedrich
>
> On Fri, Sep 23, 2011 at 12:38 AM, Rufus Pollock <rufus.pollock at okfn.org> wrote:
>> 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
>>
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> http://lists.okfn.org/mailman/listinfo/ckan-dev
>>
>
>
>
> --
> 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
>



-- 
Co-Founder, Open Knowledge Foundation
Promoting Open Knowledge in a Digital Age
http://www.okfn.org/ - http://blog.okfn.org/




More information about the ckan-dev mailing list