-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
73 lines (63 loc) · 2.5 KB
/
main.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
import threading
from time import sleep
from extras import calc_dist_km as dist
from flask import Flask, request, make_response, jsonify
import pandas as pd
from updater import updater
import json
app = Flask(__name__)
log = app.logger
data = pd.read_pickle('database1.csv')
data = updater(data)
#print(data)
#rt = RepeatedTimer(300, updater, data) # it auto-starts, no need of rt.start()
# def update():
# global data
# while True:
# data = updater(data)
# sleep(60)
# thread = threading.Thread(target=updater,args=(data,))
# # thread = threading.Thread(target=update)
# thread.start()
@app.route("/", methods=["GET"])
def main():
lat = float(request.args.get("lat"))
lon = float(request.args.get("lon"))
# print("*****************************")
print(dist(float(data['latitude']), float(data['longitude']), lat, lon))
# print("*****************************")
# req_data = data[dist(float(data['latitude']), float(data['longitude']), lat, lon) < 5000]
req_data = data
#print(req_data)
res = [{"id": str(d['spot_id']),
"latitude": str(d['latitude']),
"longitude": str(d['longitude']),
"slot_available": str(d['slot_available']),
"price": str(d['price'])} for index, d in req_data.iterrows()]
return make_response(jsonify(res))
@app.route("/detail/", methods=["GET"])
def details():
idx = str(request.args.get("id"))
if idx in data:
print("yes")
else:
print("no")
# print('something')
# print("********************************************")
# print(data[data['spot_id'] == str(idx)])
# print("********************************************")
res = {
"id": str(idx),
"latitute": str(data[data['spot_id']==idx].latitude.values[0]),
"longitude": str(data[data['spot_id']==idx].longitude.values[0]),
"rows": str(data[data['spot_id'] == idx].rows.values[0]),
"cols": str(data[data['spot_id'] == idx].cols.values[0]),
"slot_available": str(data[data['spot_id']==idx].slot_available.values[0]),
"available": list(filter(lambda x: x not in ["[", "]", ",", " "], map(str, data[data['spot_id'] == idx].available.values[0]))),
"price": str(data[data['spot_id'] == idx].price.values[0]),
"name": str(data[data['spot_id']==idx].name.values[0]),
"contact": str(data[data['spot_id']==idx].contact.values[0])
}
return make_response(jsonify(res))
if __name__ == "__main__":
app.run(debug=True, port=4040)