Skip to main content

Download organized timetable information from the Google Directions API Transit mode for pretty output

Project description

gptt

gptt (Get Public Transport Timetables) is a command line tool to download and format public transport timetables from the Google Directions API for a given day between an origin and a destination using the Transit travel mode.

Installation

The best way to install gptt is via pip: pip install gptt. You can alternatively install it from the source: python setup.py install.

Usage

Command line

gptt is primarily intended to be used as a command line tool, although its functions can be used in a Python program (see below). Using the default template, it generates detailed timetables like this one:

Example timetable

gptt -f "Budapest, Kelenföld vasútállomás" -t "Hejce" -d "2020-07-01" -k $GOOGLE_API_KEY -o timetable.html, for example, downloads all public transport connections between Budapest, Kelenföld vasútállomás (a train station in Budapest, Hungary) and Hejce (a village in Hungary) for the date July 1, 2020 using the Google Maps API key defined in the environment variable $GOOGLE_API_KEY, then format this data using the default HTML template and output it to timetable.html.

Note: the default HTML template is designed to be used for routes between, not within municipalities (it emphasizes the locality more than the actual stop name), however, you can create custom templates to suit your specific needs.

Full description of command line options:

flag option description
-h --help Show the help.
Basic arguments to get timetable data (must be passed here or in the config file):
-f --from Where to plan the route from (in a form that Google Maps would understand).
-t --to Where to plan the route to (in a form that Google Maps would understand).
-d --date The date to be used for planning in a YYYY-MM-DD format.
-k --api-key Google API key with the Directions and Geocoding API enabled.
Further arguments to customize the timetable:
-l --lang Language code used to display results, eg. 'en-GB' or 'hu' - see Google's list of supported languages. Defaults to 'en'.
--max-transfers Maximum number of allowed transfers in the results. Default is 99.
--vehicle-type-names Used to replace vehicle type names (e.g. HEAVY_RAIL or BUS with another string in the output – accepts one or more '=' separated pairs, e.g. "HEAVY_RAIL=Ⓣ" "BUS=Ⓑ".
Arguments related to the output:
-v --verbose Print diagnostic messages to stderr.
-j --json Output the results in the raw JSON format it is processed from the API.
--json-indent If the output is JSON, this many spaces will be used to indent it. If not passed, everything will be on one line.
--template Jinja2 template file to use instead of the default template. The default template is HTML, but it could be any text format, such as Markdown or LaTeX. Irrelevant when `--json` is also passed.
-o --output Output file to be written. If not given, results will be printed to stdout.
Using a config file:
-c --config Accepts a JSON file with a single object whose keys are zero or more of the options described in this table. Values should be appropriate for the option. See an example below. If given, any value present in the config will overwrite the value given by the command line flag/option.

Note: options in bold must be passed either as command line arguments or in the config file.

Using a config file

The following config.json adds values for the non-required options and the API key. (DO NOT commit your API key to a version control system!).

{
  "vehicle-type-names": ["HEAVY_RAIL=Ⓣ","BUS=Ⓑ"],
  "station-name-replacements": ["Hauptbahnhof=hbf.", "Bahnhof=bf."],
  "lang": "en-GB",
  "max-transfers": 3,
  "api-key": "ab4ab2fa-74c9-4af1-a250-9efe735c80fb"
}

Using this file, we can run gptt -f "London" -t "Manchester" -d "2020-08-19" -c config.json.

Python package

The two main functions, get_transit_plan_for_timestamp() and get_transit_plans_for_day() can be accessed by

from gptt import timetables
timetables.get_transit_plan_for_timestamp(...)
timetables.get_transit_plans_for_day(...)

Detailed documentation of these functions can be found in the code.

Contributing

Issue submissions and pull requests are welcome. Simple fixes do not require an issue to be submitted, however, do submit one if your pull request includes a lot of changes or new features.

More info

Read more about this project on my blog.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gptt-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distributions

gptt-0.1.0-py3.7.egg (20.4 kB view details)

Uploaded Egg

gptt-0.1.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file gptt-0.1.0.tar.gz.

File metadata

  • Download URL: gptt-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for gptt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4d13ba5a2d70afd68dffe22fed21afb36645c38c2030e41887a1921dc2dc2abb
MD5 bd24598fca489b44e4e85db215f27d37
BLAKE2b-256 540db1965cad230445efd2f0b5221271d3ce0fbd43178865f2e19a484577bee9

See more details on using hashes here.

File details

Details for the file gptt-0.1.0-py3.7.egg.

File metadata

  • Download URL: gptt-0.1.0-py3.7.egg
  • Upload date:
  • Size: 20.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for gptt-0.1.0-py3.7.egg
Algorithm Hash digest
SHA256 0742a3d39c7be7a628e44909550e389d61e61b41f037b7cf033edbe42a4d40a1
MD5 26a8eefaeb140d5ab92a432b6b6f7d3a
BLAKE2b-256 e5638032c70137b07401dfd125ee1b6634c96966adeb9c08bf52da5438598e46

See more details on using hashes here.

File details

Details for the file gptt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gptt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

File hashes

Hashes for gptt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84dca0a9b6e82fcf2585b16e24f7fcc553e953fe1e07028f0584cd469ba8cb2a
MD5 447f1387797bce45196f029f55b82bd9
BLAKE2b-256 4a65b861b2adffd3851b0a9d148f1f9cf56817181468ebbe3b69e81ef07f67b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page