service.py

changeset 48
428cfdf64ccc
parent 42
0b53b7c70875
child 49
5b288b0ac271
--- a/service.py	Mon Jul 31 01:15:28 2017 +0300
+++ b/service.py	Fri Aug 11 14:28:13 2017 +0300
@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-from flask import Flask, render_template, abort, send_from_directory
+from flask import Flask, render_template, abort, send_from_directory, redirect
 from datetime import datetime, date, time, timedelta
 from os import path, listdir
 from configparser import ConfigParser
@@ -77,7 +77,7 @@
 def imminent(schedule_entry):
 	return (schedule_entry['time'] - now()) <= timedelta(minutes = 3)
 
-@app.route('/pysäkki/<reference>')
+@app.route('/stop/<reference>')
 def bus_stop_schedule(reference):
 	from buses import bus_stops
 	schedule = []
@@ -120,7 +120,7 @@
 		with activate_locale():
 			return time.strftime('%-d.%-m. %H:%M').replace(' ', '\xa0')
 
-@app.route('/pysäkkiryhmä/<cluster_name>')
+@app.route('/stop_cluster/<cluster_name>')
 def cluster_schedule(cluster_name):
 	from buses import bus_stops, clusters_by_name
 	schedule = []
@@ -159,7 +159,7 @@
 		tr = tr,
 	)
 
-@app.route('/ajovuoro/<trip_reference>')
+@app.route('/trip/<trip_reference>')
 def trip(trip_reference):
 	from flask import request
 	from buses import all_trips
@@ -205,7 +205,7 @@
 		length = trip.length / 1000,
 	)
 
-@app.route('/linja/<name>')
+@app.route('/route/<name>')
 def route_page(name):
 	from buses import routes
 	route = routes[name.upper()]
@@ -224,6 +224,22 @@
 		schedule = schedule,
 	)
 
+@app.route('/')
+def index():
+	return redirect('/stop_cluster/kauppatori')
+
+@app.route('/pysäkki/<reference>')
+def redirect_pysäkki(reference):
+	return redirect('/stop/' + str(reference))
+
+@app.route('/pysäkkiryhmä/<reference>')
+def redirect_pysäkkiryhmä(reference):
+	return redirect('/stop_cluster/' + str(reference))
+
+@app.route('/ajovuoro/<reference>')
+def redirect_ajovuoro(reference):
+	return redirect('/trip/' + str(reference))
+
 @app.route('/static/<path:path>')
 def static_file(path):
 	return send_from_directory(path.join('static', path))

mercurial