Commit 94881f0d authored by Bengfort's avatar Bengfort
Browse files

create IRODs example clients

see also https://gitlab.tuebingen.mpg.de/hpc-kyb/cast2irods-server
parent 744d5847
Pipeline #12558 failed with stages
in 1 minute and 20 seconds
"""Get study metadata and subject attributes for all current studies."""
import os
import json
import requests
BASE_DIR = os.getenv('BASE_DIR', 'cast2irods')
BASE_URL = os.getenv('BASE_URL', 'http://localhost:8000')
TOKEN = os.getenv('TOKEN', '_YRJeCPMKH2-H7aNOFgTUy0iHCnm-2gp7OznR0qwxro')
def fetch(path):
r = requests.get(BASE_URL + path, headers={'Authorization': 'token ' + TOKEN})
r.raise_for_status()
return r.json()
if __name__ == '__main__':
studies = fetch('/studies/api/studies/?status=execution')
total = len(studies['studies'])
for i, study_id in enumerate(studies['studies']):
print("fetching study %i/%i" % (i + 1, total))
path = os.path.join(BASE_DIR, str(study_id))
os.makedirs(path, exist_ok=True)
info = fetch('/studies/api/studies/%i/' % study_id)
with open(os.path.join(path, 'study-info.json'), 'w') as fh:
json.dump(info, fh, indent=4)
domains = fetch('/execution/api/studies/%i/domains/' % study_id)
assert len(domains['domains']) == 1
domain = domains['domains'][0]['key']
subjects = []
pseudonyms = fetch('/execution/api/studies/%i/domains/%s/' % (study_id, domain))
for pseudonym in pseudonyms['pseudonyms']:
attributes = fetch('/execution/api/studies/%i/domains/%s/%s/attributes/' % (
study_id, domain, pseudonym
))
subjects.append({'pseudonym': pseudonym, **attributes})
with open(os.path.join(path, 'subjects.json'), 'w') as fh:
json.dump(subjects, fh, indent=4)
"""Get internal pseudonym and attributes for a single subject."""
import argparse
import os
import requests
BASE_URL = os.getenv('BASE_URL', 'http://localhost:8000')
TOKEN = os.getenv('TOKEN', '_YRJeCPMKH2-H7aNOFgTUy0iHCnm-2gp7OznR0qwxro')
GENERAL_DOMAIN = os.getenv('GENERAL_DOMAIN', '35e61660-79e4-45f7-a3d4-a1ab35537b43')
def fetch(path):
r = requests.get(BASE_URL + path, headers={'Authorization': 'token ' + TOKEN})
r.raise_for_status()
return r.json()
def get_subject_data(study_id, study_pseudonym):
domains = fetch('/execution/api/studies/%i/domains/' % study_id)
assert len(domains['domains']) == 1
study_domain = domains['domains'][0]['key']
pseudonym = fetch('/execution/api/studies/%i/domains/%s/%s/%s/' % (
study_id, study_domain, study_pseudonym, GENERAL_DOMAIN
))['pseudonym']
attributes = fetch('/subjects/api/subjects/%s/%s/attributes/' % (GENERAL_DOMAIN, pseudonym))
return {'pseudonym': pseudonym, **attributes}
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('study_id', type=int)
parser.add_argument('pseudonym')
args = parser.parse_args()
data = get_subject_data(args.study_id, args.pseudonym)
print(data)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment