Package: gptt
gpttgptt (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.InstallationThe best way to install gptt is via pip:pip install gptt. You can alternatively install it from the source:python setup.py install.UsageCommand linegptt 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 betweenBudapest, Kelenföld vasútállomás(a train station in Budapest, Hungary) andHejce(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 totimetable.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:flagoptiondescription-h--helpShow the help.Basic arguments to get timetable data (must be passed here or in the config file):-f--fromWhere to plan the route from (in a form that Google Maps would understand).-t--toWhere to plan the route to (in a form that Google Maps would understand).-d--dateThe date to be used for planning in a YYYY-MM-DD format.-k--api-keyGoogle API key with the Directions, Geocoding, and Time Zone API enabled.Further arguments to customize the timetable:-l--langLanguage code used to display results, eg. 'en-GB' or 'hu' - see Google'slist of supported languages. Defaults to 'en'.--max-transfersMaximum number of allowed transfers in the results. Default is 99.--vehicle-type-namesUsed 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--verbosePrint diagnostic messages to stderr.-j--jsonOutput the results in the raw JSON format it is processed from the API.--json-indentIf the output is JSON, this many spaces will be used to indent it. If not passed, everything will be on one line.--templateJinja2 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--outputOutput file to be written. If not given, results will be printed to stdout.Using a config file:-c--configAccepts 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: optionsin boldmust be passed either as command line arguments or in the config file.Using a config fileThe followingconfig.jsonadds 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 rungptt -f "London" -t "Manchester" -d "2020-08-19" -c config.json.Python packageThe two main functions,get_transit_plan_for_timestamp()andget_transit_plans_for_day()can be accessed byfromgpttimporttimetablestimetables.get_transit_plan_for_timestamp(...)timetables.get_transit_plans_for_day(...)Detailed documentation of these functions can be found in the code.ContributingIssue 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 infoRead more about this projecton my blog.Changelog0.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