# Copyright (C) 2022 Yuchen Pei. # # This file is part of ptvtt. # # ptvtt is free software: you can redistribute it and/or modify it under # the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # ptvtt is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General # Public License for more details. # You should have received a copy of the GNU Affero General Public # License along with ptvtt. If not, see . from urllib import parse import util import ptv_client def format_stop_and_route_name_li(stop_and_route): stop, route = stop_and_route return '
  • Stop: {}, Route: {} {} {}
  • '.format( 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 '
      {}
    '.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 """ {} {}{}{} """.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 """ {}
    Stop Route type Route number Route name
    """.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 """ {}{}{} """.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']]) def format_departure_table(departures, direction_names): return """ {}
    Estimated Scheduled Direction
    """.format(''.join( format_departure_tr(dep, direction_names) for dep in departures)) def style(): return """ """ def html(title: str, body): return """ %(title)s %(style)s

    %(title)s

    %(body)s """ % { 'title': title, 'style': style(), 'body': body } def landing_page(): title = 'PTV timetable search tool' body = """

    Query:

    """ return html(title, body)