aboutsummaryrefslogtreecommitdiff
path: root/cli_view.py
blob: 53e136027c61af3f55fd3f5531da1cf8d0a91d07 (plain) (blame)
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
# 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 <https://www.gnu.org/licenses/>.

import util
import ptv_client

def format_stop_and_route_name(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_names(stop_and_routes):
    return '\n'.join(f'[{i}] {result}' for i, result in enumerate(
        map(format_stop_and_route_name, stop_and_routes)))

def format_departures(departures, direction_names):
    return '\n'.join(['estimated: {}; scheduled: {}; direction: {}'.format(
        util.format_time(util.parse_time(dep['estimated_departure_utc'])),
        util.format_time(util.parse_time(dep['scheduled_departure_utc'])),
        direction_names[dep['direction_id']])
                      for dep in departures])