-
Notifications
You must be signed in to change notification settings - Fork 4
DataClient
Jose Miguel de la Rosa Trevin edited this page Dec 7, 2020
·
4 revisions
DataClient class allow to access the emhub REST API in an easy way.
In the following examples, we will omit the boilerplate code for creating an instance of DataClient and the authentication. This can be done as shown in the following code snippet:
from emhub.client import DataClient
dc = DataClient('https://emhub.cryoem.se/')
dc.login('my_user_name@email.com', 'my_emhub_password')
# Probably use the dc.request method to fetch data or make modifications
dc.logout()
# Get all bookings in 2020
r = dc.request('get_bookings_range', jsonData={'start': '2020-01-01', 'end': '2020-12-31'})
print(dc.json())
bookings = r.json()
print("Total bookings: ", len(bookings))
for b in bookings:
print(b['title'])
# Get all templates that are 'active'
dc.request('get_templates', jsonData={'condition': 'status="active"'})
# Modify the 'portal_iuid' for templates with ids 5 and 7
dc.request('update_template', jsonData={'attrs': {'id': 5, 'extra': {'portal_iuid': 'ec15e8114efa4cbab449a1e65d640df6'}}})
dc.request('update_template', jsonData={'attrs': {'id': 7, 'extra': {'portal_iuid': '01e5284501814e748428e70c3e35d139'}}})
Main
Admin
Applications
Development