CityOfPhiladelphia / intern-liberator

Extracts metadata records from the Metadata Catalog
1 stars 0 forks source link

Add ckan patcher #6

Open timwis opened 8 years ago

timwis commented 8 years ago

The latest version of CKAN supports package_patch, but OpenDataPhilly uses v2.2.1. So we have to use package_show, apply our updates to the result, then use package_update.

Something like:

import json

import ckanapi

@cli.command()
def patchckan():
    input_data = json.load(sys.stdin)
    current_dataset = ckanapi.action.package_show(input_data['name'])
    updated_dataset = current_dataset.update(input_data)
    result = ckanapi.action.package_update(updated_dataset)
    print(result)

With this, we should be able to do something like:

intern getdataset s0d98fs098 --format ckan | intern patchckan

(CKAN host and API key will be in .env)

It would also be nice to be able to specify which CKAN dataset to update (put its slug as a param). Though I suppose we should keep those in Benny anyway.

timwis commented 7 years ago

There's an argument to be made that ckanapi should handle this part.

EDIT: Here's a way to do that