service.py

changeset 11
e18ad36fbbf5
parent 10
843c6ee340e7
child 17
fa3c822859b5
equal deleted inserted replaced
10:843c6ee340e7 11:e18ad36fbbf5
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 from flask import Flask, render_template, abort 2 from flask import Flask, render_template, abort, send_from_directory
3 from datetime import datetime, date, time, timedelta 3 from datetime import datetime, date, time, timedelta
4 from os import path, listdir 4 from os import path, listdir
5 from configparser import ConfigParser 5 from configparser import ConfigParser
6 import locale 6 import locale
7 7
40 else: 40 else:
41 for language_name in tr.languages: 41 for language_name in tr.languages:
42 if request.args.get(language_name) is not None: 42 if request.args.get(language_name) is not None:
43 return language_name 43 return language_name
44 else: 44 else:
45 return None 45 return 'fi'
46 46
47 @app.route('/pysäkki/<tunniste>') 47 @app.route('/pysäkki/<tunniste>')
48 def pysäkkiaikataulu(tunniste): 48 def pysäkkiaikataulu(tunniste):
49 from buses import pysäkit 49 from buses import pysäkit
50 from math import ceil 50 from math import ceil
112 numero = numero, linja = ajovuoro.linja.viite, 112 numero = numero, linja = ajovuoro.linja.viite,
113 selite = ' - '.join(tr(paikka, 'paikat') for paikka in kyltti), 113 selite = ' - '.join(tr(paikka, 'paikat') for paikka in kyltti),
114 yö = yö(datetime.combine(tänään(), time()) + ajovuoro.reitti[-1].saapumisaika), 114 yö = yö(datetime.combine(tänään(), time()) + ajovuoro.reitti[-1].saapumisaika),
115 ) 115 )
116 116
117 @app.route('/static/<path:path>')
118 def static_file(path):
119 return send_from_directory(path.join('static', path))
120
117 if __name__ == '__main__': 121 if __name__ == '__main__':
118 from argparse import ArgumentParser 122 from argparse import ArgumentParser
119 parser = ArgumentParser() 123 parser = ArgumentParser()
120 parser.add_argument('-p', '--port', type = int, default = 5000) 124 parser.add_argument('-p', '--port', type = int, default = 5000)
121 parser.add_argument('-d', '--debug', action = 'store_true') 125 parser.add_argument('-d', '--debug', action = 'store_true')

mercurial