-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_calls.py
144 lines (109 loc) · 3.91 KB
/
rest_calls.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import requests
import json
def login(useremail, userpassword):
url = "http://127.0.0.1:8000/api/login"
payload = {'username': useremail,
'password': userpassword}
files = [
]
headers = {
'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request(
"POST", url, headers=headers, data=payload, files=files)
return response.json()
# print(response.text)
#login("[email protected]", "123")
def getexp_fromqueue(token):
""" """
auth_token = "Token " + token
url = "http://127.0.0.1:8000/api/experiments/queue"
payload = {}
headers = {
'Authorization': auth_token,
# 'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request("GET", url, headers=headers, data=payload)
# returns KeyError: 'experimentId' if no experiment is in Queue
return response.json()
# print(response.text)
def poststatus_running(token, experimentId):
""" """
auth_token = "Token " + token
url = f"http://127.0.0.1:8000/api/experiments/{experimentId}"
payload = {'status': 'RUNNING'}
files = [
]
headers = {
'Authorization': auth_token,
'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request(
"PATCH", url, headers=headers, data=payload, files=files)
# print(response.text)
# post_running()
def post_result(token, result):
""" """
auth_token = "Token " + token
url = "http://127.0.0.1:8000/api/results"
payload = result
# payload = json.dumps({
# "totalCounts": "50000",
# "numberOfDetectors": "4",
# "singlePhotonRate": "1500.00",
# "totalTime": "3",
# "experiment": "68c64b96-73ed-4184-9ac1-c2d3bab0e068",
# "experimentData": {
# "countratePerDetector": {
# "d1": "123",
# "d2": "123",
# "d3": "456",
# "d4": "123",
# "d5": "123",
# "d6": "456",
# "d7": "123",
# "d8": "123"
# },
# "encodedQubitMeasurements": {
# "c00": "0.123",
# "c10": "0.123",
# "c01": "0.56",
# "c11": "0.34"
# }
# }
# })
headers = {
'Authorization': auth_token,
'Content-Type': 'application/json',
'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
# post_result()
def poststatus_done(token, experimentId):
""" """
auth_token = "Token " + token
url = f"http://127.0.0.1:8000/api/experiments/{experimentId}"
payload = {'status': 'DONE'}
files = [
]
headers = {
'Authorization': auth_token,
'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request(
"PATCH", url, headers=headers, data=payload, files=files)
print(response.text)
def poststatus_failed(token, experimentId):
""" """
url = f"http://127.0.0.1:8000/api/experiments/{experimentId}"
payload = {'status': 'FAILED'}
files = [
]
headers = {
'Authorization': token,
'Cookie': 'csrftoken=a6IwyqS4I5vjwcNAT5Tm70PuiK7AFjcDVPHbyZy3I189V7eX5iK2m0AwJQoYyVUb; sessionid=5g4v77efjv0r99nziiourrzqocruyasl'
}
response = requests.request(
"PATCH", url, headers=headers, data=payload, files=files)
print(response.text)