-
Notifications
You must be signed in to change notification settings - Fork 4
one_ENCODE.py
usage: one_ENCODE.py [-h] [--infile INFILE] [--server SERVER] [--key KEY] [--keyfile KEYFILE] [--authid AUTHID] [--authpw AUTHPW] [--force-put] [--get-only] [--id ID] [--debug] POST, PATCH or PUT one ENCODE JSON object optional arguments: -h, --help show this help message and exit --infile INFILE, -i INFILE File containing the JSON object as a JSON string. --server SERVER Full URL of the server. --key KEY The keypair identifier from the keyfile. Default is --key=default --keyfile KEYFILE The keypair file. Default is --keyfile=./keypairs.json --authid AUTHID The HTTP auth ID. --authpw AUTHPW The HTTP auth PW. --force-put Force the object to be PUT rather than PATCHed. Default is False. --get-only Do nothing but get the object and print it. Default is False. --id ID URI for an object --debug Print debug messages. Default is False. Script to add one ENCODE object from a file or stdin
- keyfile exemplified in keypairs.json
- import requests, json
$ one_ENCODE.py --id ENCBS000AAA
GET the specified object from the default server using the default keypair from the keyfile; pretty-print as a JSON string; flatten embedded objects into references.
$ one_ENCODE.py --id ENCBS000AAA --key submit
Do same but from a different server from the keyfile.
$ one_ENCODE.py --id ENCBS999JSS > ENCBS999JSS.json
Save the output to a file. To make this file postable edit it and remove the server-restricted properties like schema_version. TODO: Implement --get-postable to remove the properties that make the object unpostable.
$ echo '{"@id": "/biosamples/ENCBS999JSS/", "note": "New note text"}' | one_ENCODE.py
PATCH the object identified by the @id property. In this example, replace the note with a new one. Typically, you would save the JSON in a file and cat it to stdin.
$ one_ENCODE.py --infile newjson.json
Introspect the new JSON and if value for @id exists on the server, PATCH, otherwise POST.
$ one_ENCODE.py --infile newjson.json --force-put
Use PUT instead of PATCH.
$ one_ENCODE.py --infile newjson.json --get-only
Introspect the supplied JSON, extract the ID and get the representation of that object on the server. TODO: Implement --diff