forked from LCOGT/observation-portal-api-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery_proposals.py
36 lines (29 loc) · 1.23 KB
/
query_proposals.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/env python
"""
query_proposals.py
Return details about proposals you belong to, including time allocations.
"""
import requests
API_TOKEN = 'PlaceApiTokenHere' # API token obtained from https://observe.lco.global/accounts/profile/
response = requests.get(
'https://observe.lco.global/api/proposals/',
headers={'Authorization': 'Token {}'.format(API_TOKEN)}
)
# Make sure this API call was successful
try:
response.raise_for_status()
except requests.exceptions.HTTPError as exc:
print('Request failed: {}'.format(response.content))
raise exc
proposals_dict = response.json() # API returns a json dictionary containing proposal information
print('Member of {} proposals'.format(proposals_dict['count']))
# Loop over each proposal and print some things about it.
for proposal in proposals_dict['results']:
print('\nProposal: {}'.format(proposal['id']))
for time_allocation in proposal['timeallocation_set']:
print('{0:.3f} out of {1} standard hours used on instrument types {2} for semester {3}'.format(
time_allocation['std_time_used'],
time_allocation['std_allocation'],
', '.join(time_allocation['instrument_types']),
time_allocation['semester'],
))