Giter Site home page Giter Site logo

mpolden / atb Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 1.0 104 KB

Sane API for bus data in Trondheim, Norway

Home Page: https://mpolden.no/atb/

License: BSD 3-Clause "New" or "Revised" License

Makefile 2.46% Go 97.54%
go bus-data bus-schedule atb api

atb's Introduction

atb

Build Status

A minimal API for bus data in Trondheim, Norway. This API proxies requests to Entur APIs and converts the responses into a sane JSON format.

Responses from the proxied APIs are cached. By default bus stops will be cached for 1 week and departures for 1 minute.

As of mid-August 2021 the SOAP-based AtB API no longer returns any departure data. According to this blog post on open data it appears the preferred API is now Entur. The /api/v1/ paths have therefore been removed.

Version 2 has been implemented and proxies requests to Entur instead. These are the changes in version 2:

  • There is no version 2 variant of /api/v1/busstops. Use https://stoppested.entur.org/ to find valid stop IDs.
  • Entur uses different stop IDs so old ones, such as 16011376, cannot be used in version 2. A stop includes departures in both directions by default so there is no longer a unique stop for each direction.
  • The registeredDepartureTime field may be omitted.
  • The isGoingTowardsCentrum field has moved to the departure object.

This API aims to be compatible with BusBuddy (which appears to be defunct).

Usage

$ atb -h
Usage of atb:
  -d string
    	Departure cache duration (default "1m")
  -l string
    	Listen address (default ":8080")
  -s string
    	Bus stop cache duration (default "168h")
  -x	Allow requests from other domains

API

/

Lists all available API routes.

Example:

$ curl https://mpolden.no/atb/ | jq .
{
  "urls": [
    "https://mpolden.no/atb/v2/departures"
  ]
}

/api/v2/departures

List departures from the given bus stop, identified by a stop ID. Use https://stoppested.entur.org to find stop IDs, for example 41613 (the number part of NSR:StopPlace:41613) for Prinsens gate.

Departures traveling in any direction are included by default. Add the parameter direction=inbound or direction=outbound to filter departures towards, or away from, the city centre.

Note that the claimed direction is questionable in some cases so inspect the responses to decide whether inbound or outbound makes sense for your use case.

$ curl 'https://mpolden.no/atb/v2/departures/41613?direction=inbound' | jq .

{
  "url": "https://mpolden.no/atb/v2/departures/41613",
  "departures": [
    {
      "line": "71",
      "scheduledDepartureTime": "2021-08-11T23:49:38.000",
      "destination": "Dora",
      "isRealtimeData": true,
      "isGoingTowardsCentrum": true
    },
    ...
  ]
}

atb's People

Contributors

mpolden avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

misganaa

atb's Issues

Forecasts for both directions

How can one request bus departures from a given stopId (bus direction)?

The resquest
/api/v1/departures/{node-id}
seems to return the results for an arbitrary direction for that node-id.

Thank you!

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.