-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
129 lines (90 loc) · 4.57 KB
/
app.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
from flask import Flask, request, redirect, url_for, render_template
from airtable import Airtable
from dotenv import load_dotenv
import os
import urllib
from urllib.request import urlopen, Request
import ast
import json
from datetime import datetime
load_dotenv()
app = Flask(__name__)
app.secret_key = os.getenv("KEY") # Change this!
users_table = Airtable(os.getenv("AIRTABLE_BASE"),
'Users', os.getenv("AIRTABLE_KEY"))
entry_table = Airtable(os.getenv("AIRTABLE_BASE"),
'Entries', os.getenv("AIRTABLE_KEY"))
@app.route('/', methods=['GET'])
def home():
return render_template('home.html')
@app.route('/checkin', methods=['GET', 'POST'])
def checkin():
if len(users_table.search('ID Number', request.form['idNumber'])) == 0:
return render_template('moreinfo.html', idNumber=request.form['idNumber'], storeID=request.form['storeID'])
userID = users_table.search('ID Number', request.form['idNumber'])[0]["fields"]["User ID"]
record = entry_table.match("Related Main Field", userID, sort='-Entrance Time')
if record != {}:
if record["fields"]["Exit Time Forced"] == 1:
entry_table.update_by_field('Entry Record ID', record["fields"]["Entry Record ID"], {'Exit Time': str(datetime.now())})
contacts = entry_table.get_all(filterByFormula="AND(OR(" +
'AND(IS_AFTER({Entrance Time},"' +
str(record["fields"]["Entrance Time"]) +
'"),IS_BEFORE({Entrance Time},"' +
str(datetime.now()) +
'")),' +
'AND(IS_AFTER({Exit Time},"' +
str(record["fields"]["Entrance Time"]) +
'"),IS_BEFORE({Exit Time},"' +
str(datetime.now()) +
'")),' +
'AND(IS_AFTER({Exit Time},"' +
str(record["fields"]["Entrance Time"]) +
'"),IS_BEFORE({Exit Time},"' +
str(datetime.now()) +
'")),' +
'AND(IS_BEFORE({Entrance Time},"' +
str(record["fields"]["Entrance Time"]) +
'"),IS_AFTER({Exit Time},"' +
str(datetime.now()) +
'")),' +
'AND(IS_SAME({Entrance Time},"' +
str(record["fields"]["Entrance Time"]) +
'")),' +
'AND(IS_SAME({Exit Time},"' +
str(datetime.now()) +
'"))),IF({Persons ID}!="' +
str(record["fields"]["Persons ID"]) +
'",TRUE(),FALSE()))',)
contactsID =[]
for i in contacts:
if i["fields"]["Related User"][0] != record["fields"]["Related User"][0]:
contactsID.append(i["fields"]["Related User"][0])
entry_table.update_by_field('Entry Record ID', record["fields"]["Entry Record ID"], {'Contacts': contactsID})
return render_template('donecheckout.html')
else:
entry_table.insert({"Related Place": [request.form['storeID']],
"Related User": [users_table.search('ID Number', request.form['idNumber'])[0]["id"]],
"Entrance Time": str(datetime.now()),})
return render_template('donecheckin.html')
else:
entry_table.insert({"Related Place": [request.form['storeID']],
"Related User": [users_table.search('ID Number', request.form['idNumber'])[0]["id"]],
"Entrance Time": str(datetime.now()),})
return render_template('donecheckin.html')
print(request.form['idNumber'])
return render_template('donecheckin.html')
@app.route('/registerandcheckin', methods=['GET', 'POST'])
def registerAndCheckin():
users_table.insert({'Full Name': request.form['name'], "ID Number": request.form['idNumber'],
'Street Address': request.form['address'], 'Phone Number': request.form['phone']})
entry_table.insert({"Related Place": [request.form['storeID']],
"Related User": [users_table.search('ID Number', request.form['idNumber'])[0]["id"]],
"Entrance Time": str(datetime.now()),})
print(request.form['idNumber'])
return render_template('donecheckin.html')
@app.route('/service-worker.js')
def sw():
return app.send_static_file('service-worker.js')
if __name__ == '__main__':
from os import environ
app.run(debug=False, host='0.0.0.0', port=environ.get("PORT", 5000))