-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateApp.py
48 lines (37 loc) · 1.54 KB
/
gateApp.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
#!/usr/bin/python
##################### Library Imports #####################
from sys import argv
import requests
from time import sleep
# -- ADINT Intermidiate Project
# -- Made by: Diogo Ferreira and Rafael Cordeiro
# ----------------------------------------
# --------------Gate App------------------
# ----------------------------------------
GATE_STATE = 0 #0 - closed / 1 - open
URL_SERVER = 'http://localhost:8000'
if len(argv) != 3:
print("Number of arguments is not correct!")
else:
print("Connecting to server...")
#Check if secret number is valid
CheckSecretNum = requests.get(URL_SERVER+"/Secret",allow_redirects=True, json={"secret": argv[2], "id": argv[1]}).json()
if int(CheckSecretNum['Valid']):
print("The secret is valid for this gate")
while True :
#get and send user code to server
usercode = input("Type the user code: ")
valid = requests.get(URL_SERVER+"/Usercode", allow_redirects=True, json={"code": str(usercode),"secret": argv[2],"id": argv[1]})
#check if the gate is to open or not
if valid.json()['valid'] == 'T':
print("!!! CODE VALID !!!")
GATE_STATE = 1
print("!!! The gate will close in 5 seconds !!!")
sleep(5)
break
else:
print("!!! CODE IS NOT VALID !!!")
else:
print('The secret is not valid for this gate')
print('Exiting...')
exit()