-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.py
130 lines (105 loc) · 3.72 KB
/
proxy.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
import requests
# -- ADINT Final Project
# -- Made by: Diogo Ferreira and Rafael Cordeiro
URL_DB_gates_hist = "http://localhost:8002/gate/occurrences/"
URL_DB_gates = "http://localhost:8003/gate/"
URL_DB_gates_hist_rep = "http://localhost:8004/gate/occurrences/"
URL_DB_gates_rep = "http://localhost:8005/gate/"
def listgates():
try:
Gates_list=requests.get(URL_DB_gates + "listGates", allow_redirects=True).json()
except:
try:
Gates_list=requests.get(URL_DB_gates_rep + "listGates", allow_redirects=True).json()
except:
return {'StatusCode':'0'}
return Gates_list
def creategates(gateID,gateLocation):
url1 = URL_DB_gates + "newGates"
url2 = URL_DB_gates_rep + "newGates"
try:
aux1 = requests.post(url1,json={'gateID':gateID,'gateLocation':gateLocation}, allow_redirects=True)
Flag1 = aux1.json()['StatusCode']
except:
return '0'
try:
Flag2 = requests.post(url2,json={'gateID':gateID,'gateLocation':gateLocation}, allow_redirects=True).json()['StatusCode']
except:
Flag2 = 0
if Flag1 == '1' and Flag2 == '1':
return aux1.json()['SecretNumber']
elif Flag1 == '3' or Flag2 == '3':
return '4'
elif Flag1 == '1':
return '2'
elif Flag2 == '1':
return '3'
else:
return '0'
def updateAct(gateID):
try:
aux1 = requests.get(URL_DB_gates + gateID + "/admission",allow_redirects=True)
Flag1 = aux1.json()['StatusCode']
except:
return '0'
try:
Flag2 = requests.get(URL_DB_gates_rep + gateID + "/admission",allow_redirects=True).json()['StatusCode']
except:
Flag2 = 0
if Flag1 == '1' and Flag2 == '1':
return 1
elif Flag1 == '3' or Flag2 == '3':
return 4
elif Flag1 == '1':
return 2
elif Flag2 == '1':
return 3
else:
return 0
def checkgates(gateID,gateSecret):
try:
res = requests.get(URL_DB_gates+"GateSecret/"+gateID, allow_redirects=True, json={"secret": gateSecret}).json()
except:
try:
res = requests.get(URL_DB_gates_rep+"GateSecret/"+gateID, allow_redirects=True, json={"secret": gateSecret}).json()
except:
return {'Valid':'0'}
return res
def gateshistory():
try:
res = requests.get(URL_DB_gates_hist + "history", allow_redirects=True).json()
except:
try:
res = requests.get(URL_DB_gates_hist_rep + "history", allow_redirects=True).json()
except:
return {"history": []}
return res
def gateshistorybyID(gateID):
try:
res= requests.get(URL_DB_gates_hist + str(gateID) + "/history", allow_redirects=True).json()
except:
try:
res= requests.get(URL_DB_gates_hist_rep + str(gateID) + "/history", allow_redirects=True).json()
except:
return {"history": []}
return res
def newGateOcco(gateID,status):
try:
aux1 = requests.post(URL_DB_gates_hist+"newOccurrence",json={'gate_id':gateID,'Status':status},allow_redirects=True)
Flag1 = aux1.json()['StatusCode']
except:
return '0'
try:
Flag2 = requests.post(URL_DB_gates_hist_rep+"newOccurrence",json={'gate_id':gateID,'Status':status},allow_redirects=True).json()['StatusCode']
except:
Flag2 = 0
if Flag1 == '1' and Flag2 == '1':
return 1
elif Flag1 == '3' or Flag2 == '3':
return 4
elif Flag1 == '1':
return 2
elif Flag2 == '1':
return 3
else:
return 0