Giter Club home page Giter Club logo

bart_api's Introduction

bart_api

Reuben Castelino - [email protected]

Description

A simple python package that interacts with the Bay Area Rapid Transit API.

Usage

install bart_api with:

git clone github.com/projectdelphai/bart_api
sudo python setup.py install

To create a new object:

from bart_api import BartApi

bart = BartApi()

If you have your own API key (which you can get at the BART API website), you can use that instead of the default free one with:

bart = BartApi("YOUR_API_KEY_HERE")

To get the number of live trains:

live_trains = bart.number_of_trains()

To get the status of all elevators:

elevators_status = bart.elevator_status()

All responses for now are returned as lxml etrees.

To get all recorded stations:

station_list = bart.get_stations()

This is important because you need the abbreviation necessary to find further information about a station or a route. Once you have your list of stations, you can find the abbreviation for your station by iterating through the list, comparing the name with the one you want

if entry.find("name").text == "West Oakland"

then grabbing the abbreviation:

entry.find("abbr").text

You can get the info about a station with

info = bart.station_info(station_abbr)

To get the access information of a station (directions, lockers, parking, entering and exiting):

access_info = bart.station_access(station_abbr, legend)

Legend must be in the form of "0" or "1". If nothing, it defaults to 1.

To get the estimated time of departure for a station:

departures = bart.etd(station_abbr, platform_number, direction)

The station abbreviation defaults to all if nothing else if placed. Nothing else can be used if you make station abbreviation all. If you have a specific station, you can specify either th eplatform number or the direction. The direction must be either "s" or "n" (southbound or northbound). If both are used, platform will be used over direction.

To get all routes:

routes = bart.routes(sched, date)

sched is the currently used schedule (which as of oct 27, 2013 is 32). If there is no schedule, it defaults to date which if not specified defaults to today. The date format is mm/dd/yyyy. You can also use today or now.

To get specific info about a route use:

route_info = bart.route_info(route, sched, date)

sched is used over date if both are supplied.

To run the tests to make sure everything is running well, run this command in the root directory:

python -m unittest discover

Todo

  • remove duplicate code into a better method

Helping Out

  1. Create an issue (optional)
  2. Fork the codebase
  3. Create a branch
  4. Make your changes
  5. Write tests
  6. Merge branch
  7. Make a pull request

Changelog

0.0.3

  • made methods for all but three of the schedule methods
  • started transitioning to return dicts
  • implemented easier search for item method

0.0.2

  • made methods for everything but the schedule section

0.0.1

  • working through advisory information part of api
  • designed structure for tests and packaging

bart_api's People

Contributors

pmp avatar projectdelphai avatar rdhyee avatar

Watchers

 avatar

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.