forked from bkaankuguoglu/Hoosthere
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Network.py
executable file
·91 lines (76 loc) · 2.22 KB
/
Network.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
import requests
class Network:
def __init__(self, endpoint = 'http://hoo-dev.eu-central-1.elasticbeanstalk.com/hoo/'):
self.endpoint = endpoint
def create_visit(self, username, video_id, status=0):
req = requests.post(self.endpoint + 'create_visit/', json={'username': username, 'video_id': video_id, 'status': status})
if req.status_code == 200:
json = req.json()
if 'result' in json:
return None
else:
return json['id']
else:
return None
def update_visit(self, visit_id, status=0):
req = requests.post(self.endpoint + 'update_visit/', json={'id': visit_id, 'status': status})
if req.status_code == 200:
json = req.json()
if 'result' in json:
return True
else:
return False
else:
return False
def visit_status(self, visit_id):
req = requests.get(self.endpoint + 'visit_by_id/', params={'id': visit_id})
if req.status_code == 200:
json = req.json()
if not 'status' in json:
return None
else:
return json['status']
else:
return None
def get_message(self, username):
req = requests.get(self.endpoint + 'create_message/', params={'username': username})
if req.status_code == 200:
json = req.json()
if 'result' in json:
return None, None
else:
return json['id'], json['message']
else:
return None, None
def update_message(self, message_id, status=1):
req = requests.post(self.endpoint + 'update_message/', json={'id': message_id, 'status': status})
def get_resident_name(self, username):
req = requests.get(self.endpoint + 'register_resident/', params={'username': username})
if req.status_code == 200:
json = req.json()
if not 'name' in json:
return None
else:
return json['name']
else:
return None
def get_resident_msID(self, username):
req = requests.get(self.endpoint + 'register_resident/', params={'username': username})
if req.status_code == 200:
json = req.json()
if not 'microsoft_id' in json:
return ''
else:
return json['microsoft_id']
else:
return None
def microsoft_list(self):
req = requests.get(self.endpoint + 'microsoft_list/')
l = ''
if req.status_code == 200:
json = req.json()
for j in json:
l = l + ',' + (j['microsoft_id'])
l = l[1:]
#print(l)
return l