diff options
Diffstat (limited to 'html_view.py')
-rw-r--r-- | html_view.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/html_view.py b/html_view.py index f4dc7b0..98306cb 100644 --- a/html_view.py +++ b/html_view.py @@ -1,6 +1,7 @@ +from urllib import parse import util import ptv_client -from urllib import parse + def format_stop_and_route_name_li(stop_and_route): stop, route = stop_and_route @@ -8,10 +9,12 @@ def format_stop_and_route_name_li(stop_and_route): stop['stop_name'], ptv_client.get_route_type(route['route_type']), route['route_number'], route['route_name']) + def format_stop_and_route_name_ol(stop_and_routes): return '<ol>{}</ol>'.format(''.join( map(format_stop_and_route_name_li, stop_and_routes))) + def format_stop_and_route_name_tr(stop_and_route): stop, route = stop_and_route return """ @@ -23,11 +26,11 @@ def format_stop_and_route_name_tr(stop_and_route): </td> <td>{}</td><td>{}</td><td>{}</td> </tr> -""".format( - route['route_type'], stop['stop_id'], route['route_id'], - parse.quote(stop['stop_name']), parse.quote(route['route_number']), - stop['stop_name'], ptv_client.get_route_type(route['route_type']), - route['route_number'], route['route_name']) +""".format(route['route_type'], stop['stop_id'], route['route_id'], + parse.quote(stop['stop_name']), parse.quote(route['route_number']), + stop['stop_name'], ptv_client.get_route_type(route['route_type']), + route['route_number'], route['route_name']) + def format_stop_and_route_name_table(stop_and_routes): return """ @@ -42,19 +45,24 @@ def format_stop_and_route_name_table(stop_and_routes): </table> """.format(''.join(map(format_stop_and_route_name_tr, stop_and_routes))) + def format_departure_title(stop_name, route_type, route_number): return 'Departures of {} {} at {}'.format( ptv_client.get_route_type(route_type), route_number, stop_name) + def format_departure_tr(departure, direction_names): return """ <tr> <td>{}</td><td>{}</td><td>{}</td> </tr> """.format( - util.format_time(util.parse_time(departure['estimated_departure_utc'])), - util.format_time(util.parse_time(departure['scheduled_departure_utc'])), - direction_names[departure['direction_id']]) + util.format_time(util.parse_time( + departure['estimated_departure_utc'])), + util.format_time(util.parse_time( + departure['scheduled_departure_utc'])), + direction_names[departure['direction_id']]) + def format_departure_table(departures, direction_names): return """ @@ -66,8 +74,9 @@ def format_departure_table(departures, direction_names): </tr> {} </table> -""".format(''.join(format_departure_tr(dep, direction_names) - for dep in departures)) +""".format(''.join( + format_departure_tr(dep, direction_names) for dep in departures)) + def style(): return """ @@ -77,7 +86,8 @@ def style(): </style> """ -def html(title, body): + +def html(title: str, body): return """ <!DOCTYPE html> <html> @@ -90,7 +100,12 @@ def html(title, body): %(body)s </body> </html> -""" % {'title': title, 'style': style(), 'body': body} +""" % { + 'title': title, + 'style': style(), + 'body': body + } + def landing_page(): title = 'PTV timetable search tool' |