-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_calls.py
95 lines (81 loc) · 2.71 KB
/
api_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
from PIL import Image
import requests
from io import BytesIO
import cv2
import numpy as np
import json
base_url="https://hexam.eu-gb.mybluemix.net/"
def get_test_details(test_id):
path="api/test/"
try:
print("making call: ",base_url+path+test_id)
r = requests.get(url=base_url+path+test_id, headers={'User-Agent':'test'})
print(r)
print(r.status_code)
print(r.headers)
print(r.json()['data'][0])
return r.json()['data'][0]
except:
return None
# print(get_test_details("40287c5a-7fca-4447-94e9-d8e9f3780091"))
def get_student_details(email):
path = "api/student/"
try:
print("making call: ",base_url+path+email)
r = requests.get(url=base_url + path + email)
print(r)
print(r.status_code)
print(r.headers)
print(json.loads(r.json()['data'])[0])
return json.loads(r.json()['data'])[0]
except:
return None
# get_student_details("[email protected]")
def get_student_img(email):
student_details=get_student_details(email)
print("student detatils",student_details)
try:
print("making call: ",student_details['path'])
response = requests.get(student_details['path'])
print("got img",response.content)
img = Image.open(BytesIO(response.content))
img = np.array(img)
# cv2.imshow("photo",cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
# cv2.waitKey(0)
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
except Exception as e :
print(e)
return None
# get_student_img("[email protected]")
def put_reports(test_id,student_email,tab_switches,face_suspicion,eye_suspicion,test_content):
try :
path = "api/student/report/"
# Making a PUT request
r = requests.put(base_url+path+test_id, data={'studentEmail': student_email,'faceSuspicion': face_suspicion,'eyeSuspicion': eye_suspicion,'tabSwitches': tab_switches,'test_content':test_content})
# check status code for response recieved
# success code - 200
print(r)
# print content of request
print(r.content)
return True
except:
return False
# put_reports("d7689f6c-edde-4d06-ad14-","lk@gmail",31,30,30)
# print(get_test_details("c6c76b4a-bf53-4a9e-9c33-b86e11c53371"))
#
# from PIL import Image
# import requests
# from io import BytesIO
# import cv2
# import numpy as np
# response = requests.get("https://hexam.eu-gb.mybluemix.net/uploads/1590492232629banner-test.jpg")
#
# img = Image.open(BytesIO(response.content))
# img = np.array(img)
#
# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#
# cv2.imshow("img",np.array(img) )
# while(True):
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break