GithubHelp home page GithubHelp logo

arcward / martapy Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 28 KB

Python wrapper for the MARTA Rail Realtime RESTful API

License: MIT License

Python 100.00%
python python-3 python3 api api-client api-wrapper marta

martapy's Introduction

MARTApy

Python wrapper for MARTA realtime rail and bus APIs: http://www.itsmarta.com/app-developer-resources.aspx

Installation

To install via pip, just:

$ pip install martapy

Or, locally from the same directory as setup.py:

$ python setup.py install

Rail

To get a list of train arrivals:

from martapy import RailClient

rail_client = RailClient(api_key="your_api_key")
arrivals = rail_client.arrivals()

This returns an instance of martapy.rail.Arrivals(list) which has a few handy methods to filter results further.

For example, to print the destination and waiting time for upcoming arrivals at Peachtree Center Station:

from martapy import RailClient

rail_client = RailClient(api_key="your_api_key")
peachtree_station = rail_client.arrivals().by_station('peachtree')

for arrival in peachtree_station:
    print("To: {}, When: {}".format(arrival.destination, arrival.waiting_time))
With output that would look something like::
To: Airport, When: Arriving To: Lindbergh, When: 16 min To: Doraville, When: 19 min

Filters

To narrow results, martapy.rail.Arrivals(list) has a number of properties/methods:

  • Arrivals by line: red_line blue_line green_line gold_line
  • Arrivals by direction: northbound eastbound westbound southbound
  • Arrivals by waiting time: boarding arriving arrived
  • Arrivals grouped by station name: Arrivals.stations
  • Arrivals grouped by train ID: Arrivals.trains
  • Arrivals associated with a specific station: Arrivals.by_station('station name')

These can be chained as well for more specific results. For example, to get all arrivals for the red line which are heading southbound:

from martapy.rail import RailClient

rail_client = RailClient(api_key="your_api_key")
arrivals = rail_client.arrivals().red_line.southbound

Other properties

Each Arrivals instance returned is just a list of martapy.rail.Arrival objects, with properties similar to the filters above (station, direction, event_time, line...). To get the original JSON string back, use Arrival.json.

Bus

To get a list of active buses:

from martapy import BusClient

bus_client = BusClient()
buses = bus_client.buses()

To get active buses for a particular route number, use BusClient.buses(route=111) (or any other route number)

To filter this list down further, use filter() on the returned Buses list. For example, to return only Westbound buses:

from martapy import BusClient

bus_client = BusClient()
buses = bus_client.buses().filter(direction='Westbound')

martapy's People

Contributors

arcward avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

gitrjaa

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.