-
Notifications
You must be signed in to change notification settings - Fork 1
/
tracker.py
76 lines (56 loc) · 1.77 KB
/
tracker.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
from config import AUTH_HEADER, ENDPOINT
from flask import Flask, render_template, request, make_response
import os
import requests
app = Flask("manualtracker")
headers = {}
if AUTH_HEADER != '':
headers = {
'Authorization': AUTH_HEADER
}
def update(id, lat, lon, accuracy, voltage):
update = {
'device_id': id,
'lat': lat,
'lng': lon,
'accuracy': accuracy,
'battery_voltage': voltage
}
resp = requests.post(ENDPOINT, headers=headers, data=update)
print(resp)
print(resp.text)
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
if script_name:
environ['SCRIPT_NAME'] = script_name
path_info = environ['PATH_INFO']
if path_info.startswith(script_name):
environ['PATH_INFO'] = path_info[len(script_name):]
scheme = environ.get('HTTP_X_SCHEME', '')
if scheme:
environ['wsgi.url_scheme'] = scheme
return self.app(environ, start_response)
app.wsgi_app = ReverseProxied(app.wsgi_app)
def to_dict(args):
outdict = {}
for key, val in args.items():
outdict[key] = val
return outdict
@app.route('/')
def index():
return render_template(
'tracker.html',
approot='/')
@app.route('/set_tracker', methods=['POST'])
def set_tracker():
data = to_dict(request.form)
name = data['name']
lat = data['lat']
lon = data['lon']
voltage = data['voltage']
update(name, lat, lon, 1, voltage)
return "OK"
# update('tracker2', 51.493695, 11.969930, 1, 3.6)