-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
executable file
·65 lines (56 loc) · 2.2 KB
/
Copy pathwebapp.py
File metadata and controls
executable file
·65 lines (56 loc) · 2.2 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
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Bottle template for busomatic web app
# Version : 0.2.5
from bottle import route, run, template, static_file, response, get, default_app
from src import busquery, openweather
busquery = busquery.BusQuery()
journey = busquery.journey
# Default page returned when calling the base url
@route('/')
def index():
busquery.update_feed_thread()
lines = busquery.get_lines()
forecast = openweather.forecast()
weather = forecast["weather"]
temp = forecast["temp"]
wind = forecast["wind"]
response.content_type = 'text/html;charset=utf8'
return template('index', lines=lines, weather=weather,
temp=temp, wind=wind)
# Fetch all available directions for a given line
@get('/direction/<id_ligne>')
def direction(id_ligne):
busquery.update_journey(route_id=id_ligne)
directions = busquery.get_directions(journey)
return template('directions', directions=directions)
# Fetch all available stops for a given direction
@get('/arret/<id_direction>')
def arret (id_direction):
busquery.update_journey(direction_id=id_direction)
stops = busquery.get_stops(journey)
response.content_type = 'text/html;charset=utf8'
return template('stop', stops=stops)
# Request schedule for a given stop
@get('/horaire/<id_arret>')
def horaires(id_arret):
busquery.update_journey(stop_id=id_arret)
select_schedule = busquery.select_schedule(journey, id_arret)
schedules = select_schedule['schedule']
#is_realtime = select_schedules['is_realtime']
if schedules:
return template('schedule', schedules=schedules)
else:
return '<h3 style="padding-top:20px;text-align:center;">Aucun passage prévu</h3>'
# Paths to static files (scripts, images, stylesheet,...)
@get('/static/<filename:path>')
def send_static(filename):
return static_file(filename, root='static/')
# Starts integrated web server if directly called (e.g 'python webapp.py')
# But remember to NOT use it in production, this is only for testing purposes
if __name__ == '__main__':
run(host='0.0.0.0', port=8080, reloader=True)
# Or launch bottle in application mode wich is interfacing with uwsgi
else:
app = application = default_app()