aboutsummaryrefslogtreecommitdiff
path: root/ptv.py
blob: 7644c922e395957c840c6952bfa24a4a99b21b64 (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
37
38
39
40
41
42
43
# 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 ptv_client
import cli_view
import util


def main():
    stop_and_routes = list(
        ptv_client.get_stop_and_routes(ptv_client.search(input('Query: '))))
    if not stop_and_routes:
        print("No results")
        return
    print(cli_view.format_stop_and_route_names(stop_and_routes))
    idx = int(input('Choose a number: '))
    print(cli_view.format_stop_and_route_name(stop_and_routes[idx]))
    departures = ptv_client.get_departures_from_stop_and_route(
        *stop_and_routes[idx])
    filtered_deps = util.filter_departures(departures['departures'])
    print(
        cli_view.format_departures(
            filtered_deps,
            ptv_client.get_direction_names(
                stop_and_routes[idx][1]['route_id'])))


if __name__ == "__main__":
    main()