Coder Social home page Coder Social logo

blinktaginc / transit-departures-widget Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 5.0 709 KB

Build a realtime transit departures widget from GTFS and GTFS-Realtime Data.

License: MIT License

JavaScript 81.86% Pug 8.99% CSS 9.02% Shell 0.13%
gtfs gtfs-rt gtfs-realtime transit transit-data

transit-departures-widget's Introduction

➡️ Command Line Usage | Configuration ⬅️

Transit Departures Widget



Build a realtime transit departures lookup widget from GTFS and GTFS-Realtime.

NPM


Transit Departures Widget generates a user-friendly transit realtime departures widget in HTML format directly from GTFS and GTFS-RT transit data. Most transit agencies have schedule data in GTFS format and many publish realtime departures using GTFS-Realtime. This project generates HTML, JS and CSS for use on a transit agency website to allow users to see when the next vehicle is departing from a specific stop.

transit-departures-widget1

Lookup by route, direction and stop

transit-departures-widget2

Lookup by stop name

transit-departures-widget3

Lookup by stop code

Users can lookup departures by choosing a route, direction and stop or by entering stop id directly. If a stop code is entered, departures for all routes serving that stop are shown.

Features:

  • Auto-refreshes departures every 20 seconds. (configurable with the refreshIntervalSeconds parameter)

  • Caches departures so looking up additional stops is instantaneous.

  • Typeahead autocomplete of stop names makes it easy to look up stops by name.

  • Appends stop_id to URL to support linking to departures for a specific stop or bookmarking the page.

  • Uses route_color and route_text_color for a stop circle in results.

  • Fetches GTFS-RT data directly - no server-side code is needed.

  • Supports creation of custom HTML templates for complete control over how the widget is rendered.

Demo

An demo of the widget is available at https://transit-departures-widget.blinktag.com/. Note that this demo will only return departures during hours where vehicles for the demo agency is operating, roughly 7 AM to 10 PM Pacific time.

Current Usage

The following transit agencies use transit-departures-widget on their websites:

Command Line Usage

The transit-departures-widget command-line utility will download the GTFS file specified in config.js and then build the transit departures widget and save the HTML, CSS and JS in html/:agency_key.

If you would like to use this library as a command-line utility, you can install it globally directly from npm:

npm install transit-departures-widget -g

Then you can run transit-departures-widget.

transit-departures-widget

Command-line options

configPath

Allows specifying a path to a configuration json file. By default, transit-departures-widget will look for a config.json file in the directory it is being run from.

transit-departures-widget --configPath /path/to/your/custom-config.json

skipImport

Skips importing GTFS into SQLite. Useful if you are rerunning with an unchanged GTFS file. If you use this option and the GTFS file hasn't been imported, you'll get an error.

transit-departures-widget --skipImport

Configuration

Copy config-sample.json to config.json and then add your projects configuration to config.json.

cp config-sample.json config.json
option type description
agency object Information about the GTFS and GTFS-RT to be used.
beautify boolean Whether or not to beautify the HTML output.
endDate string A date in YYYYMMDD format to use to filter calendar.txt service. Optional, defaults to using all service in specified GTFS.
locale string The 2-letter code of the language to use for the interface.
noHead boolean Whether or not to skip the header and footer of the HTML document.
refreshIntervalSeconds integer How often the widget should refresh departure data in seconds. Optional, defaults to 20 seconds.
skipImport boolean Whether or not to skip importing GTFS data into SQLite.
sqlitePath string A path to an SQLite database. Optional, defaults to using an in-memory database.
startDate string A date in YYYYMMDD format to use to filter calendar.txt service. Optional, defaults to using all service in specified GTFS.
templatePath string Path to custom pug template for rendering widget.
timeFormat string The format (12hour or 24hour) for the "as of" display.

agency

{Object} Specify the GTFS file to be imported in an agency object. Static GTFS files can be imported via a url or a local path.

agency_key is a short name you create that is specific to that GTFS file.

gtfs_static_url is the URL of an agency's static GTFS. Either gtfs_static_url or gtfs_static_path is required.

gtfs_static_path is the local path to an agency's static GTFS on your local machine. Either gtfs_static_url or gtfs_static_path is required.

gtfs_rt_tripupdates_url is the URL of an agency's GTFS-RT trip updates. Note that the GTFS-RT URL must support CORS in order for the widget to work.

  • Specify a download URL for static GTFS:
{
  "agency": {
    "agency_key": "marintransit",
    "gtfs_static_url": "https://marintransit.org/data/google_transit.zip",
    "gtfs_rt_tripupdates_url": "https://marintransit.net/gtfs-rt/tripupdates"
  }
}
  • Specify a path to a zipped GTFS file:
{
  "agency": {
    "agency_key": "marintransit",
    "gtfs_static_path": "/path/to/the/gtfs.zip",
    "gtfs_rt_tripupdates_url": "https://marintransit.net/gtfs-rt/tripupdates"
  }
}
  • Specify a path to an unzipped GTFS file:
{
  "agency": {
    "agency_key": "marintransit",
    "gtfs_static_path": "/path/to/the/unzipped/gtfs",
    "gtfs_rt_tripupdates_url": "https://marintransit.net/gtfs-rt/tripupdates"
  }
}

beautify

{Boolean} Whether or not to beautify the HTML output. Defaults to false.

    "beautify": false

endDate

{String} A date in YYYYMMDD format to use to filter service_ids in calendar.txt. Useful in combination with startDate configuration option. Optional, if not specified, all services in GTFS will be used.

    "endDate": "20240401"

locale

{String} The 2-letter language code of the language to use for the interface. Current languages supported are Polish (pl) and English (en). Pull Requests welcome for translations to other languages. Defaults to en (English).

    "locale": "en'

noHead

{Boolean} Whether or not to skip the HTML head and footer when generating the HTML for the widget. This is useful for creating embeddable HTML without <html>, <head> or <body> tags. Defaults to false.

    "noHead": false

refreshIntervalSeconds

{Integer} How often the widget should refresh departure data in seconds. Optional, defaults to 20 seconds.

    "refreshIntervalSeconds": 30

skipImport

{Boolean} Whether or not to skip importing from GTFS into SQLite. Useful for re-running the script if the GTFS data has not changed. If you use this option and the GTFS file hasn't been imported or you don't have an sqlitePath to a non-in-memory database specified, you'll get an error. Defaults to false.

    "skipImport": false

startDate

{String} A date in YYYYMMDD format to use to filter service_ids in calendar.txt. Useful in combination with endDate configuration option. Optional, if not specified, all services in GTFS will be used.

    "startDate": "20240301"

sqlitePath

{String} A path to an SQLite database. Optional, defaults to using an in-memory database.

    "sqlitePath": "/tmp/gtfs"

templatePath

{String} Path to a folder containing (pug)[https://pugjs.org/] template for rendering the widget widget. This is optional. Defaults to using the templates provided in views/widget. All files within the /views/custom folder will be .gitignored, so you can copy the views/widget folder to views/custom/myagency and make any modifications needed. Any custom views folder should contain pug templates called widget.pug and widget_full.pug.

    "templatePath": "views/custom/my-agency/"

timeFormat

{String} The format (12hour or 24hour) for the "as of" display. Defaults to 12hour.

    "timeFormat": "12hour"

Previewing HTML output

It can be useful to run the example Express application included in the app folder as a way to quickly preview all routes or see changes you are making to custom template.

After an initial run of transit-departures-widget, the GTFS data will be downloaded and loaded into SQLite.

You can view an individual route HTML on demand by running the included Express app:

node app

By default, transit-departures-widget will look for a config.json file in the project root. To specify a different path for the configuration file:

node app --configPath /path/to/your/custom-config.json

Once running, you can view the HTML in your browser at localhost:3000

Notes

transit-departures-widget uses the node-gtfs library to handle importing and querying GTFS data.

Contributing

Pull requests are welcome, as is feedback and reporting issues.

transit-departures-widget's People

Contributors

brendannee avatar emerzh avatar wkulesza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

transit-departures-widget's Issues

unable to install after update

Hi,
after updating (and even now when git cloning 0.1.4 tag), i'm getting this error after clone, edit of config.json and running npm install:

root@vpsXXXXX:/home/wojciech/transit-arrivals-widget# npm install transit-arrivals-widget --unsafe-perm --allow-root -g
npm ERR! code 128
npm ERR! Command failed: git clone --mirror -q https://[email protected]/mapbox/node-sqlite3.git /root/.npm/_cacache/tmp/git-clone-f290504d/.git
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-f290504d/.git'
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-10-16T19_30_05_191Z-debug.log

Please help. When trying to git clone and then npm install as normal user, im getting errors as normal user has access to node v8.10.0 only and other errors popup like: Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/transit-arrivals-widget

exports is not defined

Getting the following when running it from the command line:

dublinbus: Generating Transit Arrivals Widget HTML
Error: exports is not defined
[  Error: exports is not defined
]

No idea what this is in relation to. Here's the full output

Starting GTFS import for 1 file using SQLite database at :memory:
Downloading GTFS from https://www.transportforireland.ie/transitData/Data/GTFS_All.zip
Download successful
Importing GTFS from /var/folders/hm/ts1l6x0j2ddcn2cpzbzz14lr0000gp/T/tmp-35682-OyFNB8u4ortL/gtfs.zip
Importing - agency.txt - 115 lines imported
Importing - areas.txt - No file found
Importing - attributions.txt - No file found
Importing - calendar_dates.txt - 946 lines imported
Importing - calendar.txt - 379 lines imported
Importing - fare_attributes.txt - No file found
Importing - fare_leg_rules.txt - No file found
Importing - fare_products.txt - No file found
Importing - fare_rules.txt - No file found
Importing - fare_transfer_rules.txt - No file found
Importing - feed_info.txt - No file found
Importing - frequencies.txt - No file found
Importing - levels.txt - No file found
Importing - pathways.txt - No file found
Importing - routes.txt - 830 lines imported
Importing - shapes.txt - 6229762 lines imported
Importing - stop_areas.txt - No file found
Importing - stop_times.txt - 5927119 lines imported
Importing - stops.txt - 13191 lines imported
Importing - transfers.txt - No file found
Importing - translations.txt - No file found
Importing - trips.txt - 204876 lines imported
Completed GTFS import for 1 agency

dublinbus: Generating Transit Arrivals Widget HTML
Error: exports is not defined
[  Error: exports is not defined
]

and my config.json

{
    "agency": {
      "agency_key": "dublinbus",
      "gtfs_static_url": "https://www.transportforireland.ie/transitData/Data/GTFS_All.zip",
      "gtfs_rt_tripupdates_url": "https://api.nationaltransport.ie/gtfsr/v2/gtfsr?format=json"
    },
    "beautify": true,
    "locale": "en",
    "noHead": false,
    "refreshIntervalSeconds": 20,
    "templatePath": "views/widget",
    "timeFormat": "12hour"
  }

ERR_INVALID_ARG_TYPE on first run

Hi,

I'm trying to run this with some GTFS files from a local transport agency and I get this


Starting GTFS import for 1 file using SQLite database at database.sqlite
Importing GTFS from data
Importing - agency.txt - 1 lines imported
Importing - areas.txt - No file found
Importing - attributions.txt - No file found
Importing - calendar_dates.txt - 5061 lines imported
Importing - calendar.txt
Importing - fare_attributes.txt - No file found
Importing - fare_leg_rules.txt - No file found
Importing - fare_products.txt - No file found
Importing - fare_rules.txt - No file found
Importing - fare_transfer_rules.txt - No file found
Importing - feed_info.txt - No file found
Importing - frequencies.txt - No file found
Importing - levels.txt - No file found
Importing - pathways.txt - No file found
Importing - routes.txt - 53 lines imported
Importing - shapes.txt - 89223 lines imported
Importing - stop_areas.txt - No file found
Importing - stop_times.txt - 92446 lines imported
Importing - stops.txt - 562 lines imported
Importing - transfers.txt - No file found
Importing - translations.txt - No file found
Importing - trips.txt - 3405 lines imported
Completed GTFS import for 1 agency

MYAGENCY: Generating Transit Departures Widget HTML
Warning: route_id 962 has no directions - skipping

Error: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
[  Error: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received u  ndefined
] {
  code: 'ERR_INVALID_ARG_TYPE'
}

Thanks!

No upcoming arrivals for all requests

Hi,
great widget and simple idea that can work for almost all cases.
I'm trying to get it to work - having two urls at the same server and trying to find departures, but no matter which route+direction+stop I choose, i get: No upcoming arrivals

How to debug it? Console says 200 OK for all answers, and provides a response with a long alphanumeric value.
All requests seem to go to tripupdates url with suffix ?cacheBust=1629829331976 etc.

Please advise how to proceed.

Cannot get working for arrival time

image


{
  "agency": {
    "agency_key": "youragency",
    "gtfs_static_url": "http://www.viainfo.net/BusService/google_transit.zip",
    "gtfs_rt_tripupdates_url": "tripupdates.pb"
  },
  "beautify": true,
  "locale": "en",
  "noHead": false,
  "refreshIntervalSeconds": 20,
  "templatePath": "views/widget",
  "timeFormat": "12hour",
  "sqlitePath": "gtfs"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.