-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
84 lines (63 loc) · 1.88 KB
/
Copy pathapp.py
File metadata and controls
84 lines (63 loc) · 1.88 KB
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
import threading
import json
from flask import Flask, jsonify, request
from src.alerts import fetch_alerts, get_alerts_data
from src.gtfs import fetch_gtfs, get_gtfs_data, get_gtfs_feed_info
from src.live_tracking import (
fetch_rtf,
get_rtf_data,
add_delay,
send_notifs,
delete_delay,
)
from src.stops import fetch_stops, get_stops_data
from src.vehicles import fetch_vehicles, get_vehicles_data
app = Flask(__name__)
@app.route("/")
@app.route("/rtf")
def get_rtf():
return jsonify(get_rtf_data())
@app.route("/alerts")
def get_alerts():
return jsonify(get_alerts_data())
@app.route("/gtfs")
def get_gtfs():
return jsonify(get_gtfs_data())
@app.route("/stops")
def get_all_stops():
return jsonify(get_stops_data())
@app.route("/gtfs-feed-info")
def get_gtfs_date():
return jsonify(get_gtfs_feed_info())
@app.route("/vehicles")
def get_vehicles():
return jsonify(get_vehicles_data())
@app.route("/delayNotifs", methods=["POST"])
def get_delayNotifs():
body = json.loads(request.data)
trip = body.get("tripId")
deviceToken = body.get("deviceToken")
stop = body.get("stopId")
add_delay(trip, stop, deviceToken)
return jsonify({"success": True})
@app.route("/deleteDelayNotifs", methods=["POST"])
def get_deleteDelayNotifs():
body = json.loads(request.data)
trip = body.get("tripId")
deviceToken = body.get("deviceToken")
stop = body.get("stopId")
delete_delay(trip, stop, deviceToken)
return jsonify({"success": True})
def setup_events():
alerts_event, gtfs_event, rtf_event, stops_event, vehicles_event = [
threading.Event() for _ in range(5)
]
fetch_alerts(alerts_event)
fetch_gtfs(gtfs_event)
fetch_rtf(rtf_event)
fetch_stops(stops_event)
fetch_vehicles(vehicles_event)
send_notifs()
setup_events()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)