Created
July 22, 2020 15:13
-
-
Save stuzart/603376877d3f7e3f1a284e314a0f171e to your computer and use it in GitHub Desktop.
basic registering a workflow with workflow hub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import string | |
import getpass | |
base_url = 'https://testing2.fair-dom.org' | |
containing_project_id = 1 | |
token = "" | |
"""Set up the headers and authenticate just as in the earlier steps.""" | |
headers = {"Content-type": "application/vnd.api+json", | |
"Accept": "application/vnd.api+json", | |
"Accept-Charset": "ISO-8859-1", | |
"Authorization": "Token " + token} | |
session = requests.Session() | |
session.headers.update(headers) | |
workflow = {} | |
workflow['data'] = {} | |
workflow['data']['type'] = 'workflows' | |
workflow['data']['attributes'] = {} | |
workflow['data']['attributes']['title'] = 'my lovely workflow as an ro crate2' | |
workflow['data']['attributes']['description'] = 'a workflow added through the api' | |
workflow['data']['attributes']['license'] = 'AFL-3.0' | |
workflow['data']['attributes']['policy'] = {'access':'download'} | |
workflow['data']['relationships'] = {} | |
workflow['data']['relationships']['projects'] = {} | |
workflow['data']['relationships']['projects']['data'] = [{'id' : containing_project_id, 'type' : 'projects'}] | |
"""We describe a Content Blob just as it is was described in a earlier step. In this case we use the url key, and point to an available file (not webpage). In this case a copy of the FAIRDOM logo in our Github repository. A custom filename has also been provided, without this the filename would be determined from the link.""" | |
remote_blob = {'url' : 'https://workflowhub.eu/workflows/43/ro_crate?version=1', 'original_filename':'ro.crate.zip'} | |
workflow['data']['attributes']['content_blobs'] = [remote_blob] | |
"""Just as before, the data file and content blob is registered in one step with a POST to the data_files root.""" | |
r = session.post(base_url + '/workflows', json=workflow) | |
r.raise_for_status() | |
"""The resulting JSON should provde the details about the created Workflow. Note that in the content blob details, the size and content_type have automatically been determined by inspecting the URL (a HEAD request is used).""" | |
populated_workflow = r.json() | |
print(populated_workflow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment