Generate HTML transit timetables in from GTFS.
npm install
Copy config-sample.js
to config.js
.
cp config-sample.js config.js
Before you can use gtfs-to-html you must specify the transit agencies you'd like to use.
You can specify agencies using a url
to the GTFS file or a local path
.
To find an agency's GTFS URL, visit transitfeeds.com. You can use the direct URL from the agency or you can use a URL generated from the transitfeeds.com API along with your API token.
- Specify a download URL:
{
agency_key: 'county-connection',
url: 'http://cccta.org/GTFS/google_transit.zip'
}
- Specify a path to a zipped GTFS file:
{
agency_key: 'localAgency',
path: '/path/to/the/gtfs.zip'
}
- Specify a path to an unzipped GTFS file:
{
agency_key: 'localAgency',
path: '/path/to/the/unzipped/gtfs/'
}
The mongodb URI should also be configured in config.js
. The default database URI is:
mongodb://localhost:27017/gtfs
The following items can be added to the configuration object:
{String} This is printed at the top of the timetable.
effectiveDate: 'July 8, 2015'
{String} The symbol to be used when a specific trip does not serve a specified stop.
noServiceSymbol: '—'
{String} The symbol to be used to indicate that riders must request a stop.
requestStopSymbol: '***'
{Boolean} Whether or not to show a map of the route on the timetable.
showMap: false
This project requires that an additional file timetables.txt
be added to an agencies GTFS. This file specifies which HTML timetables should be built.
An example of this file is located in examples/timetables.txt. The format of this file is:
column name | description |
---|---|
timetable_id |
A unique ID for the timetable |
route_id |
The ID of the route the timetable is for from routes.txt . |
direction_id |
The direction_id from trips.txt for the timetable. This can be blank. |
start_date |
The start date for this timetable in YYYY-MM-DD format. |
end_date |
The end date for this timetable in YYYY-MM-DD format. |
monday |
A binary value that indicates whether this timetable should include service on Mondays. Valid options are 0 and 1 . |
tuesday |
A binary value that indicates whether this timetable should include service on Tuesdays. Valid options are 0 and 1 . |
wednesday |
A binary value that indicates whether this timetable should include service on Wednesdays. Valid options are 0 and 1 . |
thursday |
A binary value that indicates whether this timetable should include service on Thursdays. Valid options are 0 and 1 . |
friday |
A binary value that indicates whether this timetable should include service on Fridays. Valid options are 0 and 1 . |
saturday |
A binary value that indicates whether this timetable should include service on Saturdays. Valid options are 0 and 1 . |
sunday |
A binary value that indicates whether this timetable should include service on Sundays. Valid options are 0 and 1 . |
route_label |
A short text label describing the route, for instance "4". |
service_notes |
Text shown on the timetable about the service represented, for instance "Mon-Fri". |
Ensure than mongodb is running locally.
mongod
To generate HTML timetables, run the 'gtfs-to-html' script.
npm run gtfs-to-html
This will download the GTFS file specified in config.js
. Then, it will build the HTML timetables and save them in html/:agency_key
.
Note the use of two sets of --
when running commands with arguments from npm.
nohead
npm run gtfs-to-html -- --nohead
This will generate embeddable HTML without an <html>
, <head>
or <body>
tag.
After an initial run of the gtfs-to-html
script, the GTFS data will be downloaded and loaded into mongo.
You can view an individual route HTML on demand by running the included express app:
DEBUG=gtfs-to-html npm start
With this running, you can open http://localhost:3000 in your browser and view all timetables. Note that this only works after GTFS has been imported to mongodb and mongodb is running locally.