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:
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, Geocoding, and Time Zone 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.
Changelog
- 0.1.1:
- [bugfix] Fixed a bug when certain localities were not parsed correctly from API response (#1)
- [bugfix] Made the program aware of the local time of the origin of the query to define the day (#2)
- [bugfix] (partial): Better handling of the Routing API not returning transit results. This is not entirely resolved (#3)
- 0.1.0:
- initial public release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file gptt-0.1.1.tar.gz
.
File metadata
- Download URL: gptt-0.1.1.tar.gz
- Upload date:
- Size: 15.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 028653f9462feeff45e1311703f426f7ef818d4e2d7370fdaa8c0cae9c93b08f |
|
MD5 | 7f32824b56d83147439e2f252cb7029c |
|
BLAKE2b-256 | cc1cc68b1f2574220f84b8eeb90039144989fb375e6f0b4ec7ffcddfb42d3466 |
File details
Details for the file gptt-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: gptt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | def412b8590b6df014a482a90454946caaee3f8a383ed094b9d94aa45f226ab7 |
|
MD5 | 20ce01556a37e21a3a4c945aa27f5004 |
|
BLAKE2b-256 | ed6405286a3e8f51441725b0186e988b9469f77d4d26c30f6b85ba17084a0a30 |