Code Monkey home page Code Monkey logo

node-gtfs-realtime's Introduction

➡️ Installation | Quick Start ⬅️

node-GTFS-Realtime



Download GTFS-Realtime data as JSON

NPM


GTFS-realtime transit data is in protobuf format which means its not human-readable by default. node-GTFS-Realtime aims to make it fast and easy to inspect GTFS-realtime data by providing a one-line command for downloading GTFS-realtime format data and converting to JSON.

Run it right now from your command line:

npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx

The command above will fetch BART's GTFS-Realtime trip updates and save them to a file to the current directory in JSON format, named like gtfs-realtime-2022-05-28T002330.164Z.json (using the current time). You can open the resulting file in a text editor to review.

node-GTFS-Realtime can be used as a command-line tool or as a node.js module.

Example JSON

Below is an example of the JSON result for a GTFS-Realtime Trip Updates request:

{
  "header": {
    "gtfsRealtimeVersion": "1.0",
    "incrementality": "FULL_DATASET",
    "timestamp": "1653701655"
  },
  "entity": [
    {
      "id": "1001663",
      "tripUpdate": {
        "trip": {
          "tripId": "1001663",
          "scheduleRelationship": "SCHEDULED"
        },
        "stopTimeUpdate": [
          {
            "stopSequence": 13,
            "arrival": {
              "delay": 25,
              "time": "1653701754",
              "uncertainty": 30
            },
            "departure": {
              "delay": 25,
              "time": "1653701775",
              "uncertainty": 30
            },
            "stopId": "SANL"
          }
        ]
      }
    }
  ]
}

Installation

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

npm install gtfs-realtime -g

Or you can use it directly via npx:

npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx

If you are using this as a node module as part of an application, you can include it in your project's package.json file.

Quick Start

Command-Line Examples

Run via npx:

npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx

If installed globally:

gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx

With custom HTTP headers

gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --header "Authorization: bearer 1234567"

Code example

import gtfsRealtime from 'gtfs';

const config = {
  url: 'http://api.bart.gov/gtfsrt/tripupdate.aspx',
  output: '/path/to/save/file.json',
  header: ['Authorization: bearer 12345'],
};

gtfsRealtime(config)
  .then(() => {
    console.log('Import Successful');
  })
  .catch((err) => {
    console.error(err);
  });

Command-Line Usage

gtfs-realtime [options...] <url>

The `gtfs-realtime` command-line utility will download GTFS-Realtime data from the specified URL and save it as a JSON file.

### Options

`-s, --silent`

Hides all console output

    gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --silent

`-H, --header`

Specify one or more HTTP headers to be included in the request.

    gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --header "Authorization: bearer 1234567" --header "test:true"

`-o, --output`

Specify a path to save the JSON file. Optional, defaults to the current directory using a filename with the current time.

    gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx --output /path/to/save/file.json

`--help`

Show help.

    gtfs-realtime --help

`--version`

Show version

    gtfs-realtime --version

## Contributing

Pull requests are welcome, as is feedback and [reporting issues](https://github.com/blinktaginc/node-gtfs-realtime/issues).

### Linting

    npm run lint

node-gtfs-realtime's People

Contributors

brendannee avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

jakemauer

node-gtfs-realtime's Issues

BART example in README errors

Hi there - great project, I'm actually hoping to use it with BART's feed. However, the example in the README errors like so:

% npx gtfs-realtime http://api.bart.gov/gtfsrt/tripupdate.aspx

Downloading GTFS-Realtime from http://api.bart.gov/gtfsrt/tripupdate.aspx
Error: https://api.bart.gov/gtfsrt/tripupdate.aspx: 403 Forbidden

Error: https://api.bart.gov/gtfsrt/tripupdate.aspx: 403 Forbidden
[  Error: 403 Forbidden

  - gtfs-realtime.js:18 gtfsRealtime
    [d5e1ab7c0c5fdcf3]/[gtfs-realtime]/lib/gtfs-realtime.js:18:19

  - task_queues:95 process.processTicksAndRejections
    node:internal/process/task_queues:95:5

  - gtfs-realtime.js:50 async setupImport
    [d5e1ab7c0c5fdcf3]/[gtfs-realtime]/bin/gtfs-realtime.js:50:3

] {...

I went here: https://www.bart.gov/schedules/developers/gtfs-realtime

And checked the feed URL from BART and got https://api.bart.gov/gtfsrt/tripupdate.aspx from them. Then tried that (https URL rather than http) but same issue:

 % npx gtfs-realtime https://api.bart.gov/gtfsrt/tripupdate.aspx


Downloading GTFS-Realtime from https://api.bart.gov/gtfsrt/tripupdate.aspx
Error: https://api.bart.gov/gtfsrt/tripupdate.aspx: 403 Forbidden

Error: https://api.bart.gov/gtfsrt/tripupdate.aspx: 403 Forbidden
[  Error: 403 Forbidden

Is this something you've come across? I'll dig around and see if I can figure out what's causing the 403 from BART.

Open to elaboration of usage as a library

Hello!
I was evaluating libraries for a real-time project, saw node-gtfs might be a good beginning point and then noticed the start of this project! The project would be consuming GTFS-rt data and it looks like you've got a base going here. I wanted to check before diving in if y'all would be open to PRs that further develop the tools available to folks who would use node-gtfs-realtime as a library, things like processing and query tools, Typescript bindings, etc.

Thanks so much!

Thanks for writing this

I just started poking at the BART GTFS-RT api and was VERY confused at the output. Thanks for writing this project, it's going to be an essential part of whatever I end up building.

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.