-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
66 lines (50 loc) · 2.11 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
import os
import random
from flask import Flask, request, Response, send_from_directory, render_template
from multiprocessing import Process
import subprocess
from bookingfuncs import notify_close_cars
# For local testing Only:
from dotenv import load_dotenv
load_dotenv()
subprocess.run(["playwright", "install", "chromium"])
# Check keys when program start
KEYS = os.getenv('KEYS')
if not KEYS:
print('Missing KEYS environment variable.')
os._exit(1)
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def main_function():
# import keys from environment variables
keys = dict(item.split(':') for item in KEYS.split(','))
if request.method == 'GET':
if request.args.get('key') not in keys.values():
return 'API key is needed'
return render_template('index.html')
if request.method == 'POST':
if request.args.get('key') not in keys.values():
return 'API key is needed'
loc = [float(request.form.get('latitude')), float(request.form.get('longitude'))]
max_dis = float(request.form.get('radius'))
api_key = request.form.get('key')
login_cred = request.form.get('login_cred')
autobook = request.form.get('autobook')
ethical = request.form.get('ethical')
p = Process(target=notify_close_cars, args=(loc, max_dis, api_key,autobook,login_cred, ethical,), name=f'{api_key}{random.randint(10000, 99999)}')
p.start()
if login_cred=='' and autobook is not None:
return render_template('requested.html', warn=True)
else:
return render_template('requested.html', warn=False)
@app.route('/docs')
def docs():
return render_template('docs.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory(app.root_path, 'static/images/favicon.ico', mimetype='image/vnd.microsoft.icon')
@app.route('/mylocation.png')
def mylocation():
return send_from_directory(app.root_path, 'static/images/mylocation.png', mimetype='image/png')
if __name__ == '__main__':
app.run(debug=False)