-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_backup.py
68 lines (54 loc) · 1.6 KB
/
app_backup.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
from datetime import datetime
import requests
import json
import time
import pickle
d = {}
# Open the file in binary mode
with open("backup.pkl", "rb") as file:
# Call load method to deserialze
d = pickle.load(file)
print(d)
url_post = "https://web-production-c873.up.railway.app/attendance_in"
url_update = "https://web-production-c873.up.railway.app/attendance_out"
headers = {
"Content-Type": "application/json; charset=utf-8",
"x-hasura-admin-secret": "4E9fBl6pQoyEL138Ov9jmoY3xnKtMpKm2KtrHWHPOUdcXzMHBzvII9CDooZZH5Ay",
}
def backup(d):
# Open a file and use dump()
with open("backup.pkl", "wb") as file:
# A new file will be created
pickle.dump(d, file)
def outentry(id, key):
print("outentry")
now = datetime.now() # current date and time
data_out_time = {"id": int(id), "out_time": datetime.timestamp(now)}
response = requests.patch(url_update, headers=headers, json=data_out_time)
print(response.json())
del d[key]
print(d)
backup(d)
def inentry(key):
print("inentry")
now = datetime.now() # current date and time
data_in_time = {"rfid_key": key, "in_time": datetime.timestamp(now)}
print("here", data_in_time)
try:
response = requests.post(url_post, headers=headers, json=data_in_time)
data = response.json()
print(data)
d[key] = data["id"]
print(d)
backup(d)
except Exception as e:
print(e)
def tap(key):
print("keys", d.keys())
if key in d.keys():
outentry(d[key], key)
else:
inentry(key)
while 1:
ip = input()
tap(ip)