Git Product home page Git Product logo

cta's Introduction

Chicago Transit Authority API

The CTA has three public endpoints for tracking CTA trains. This client supports those endpoints.

The CTAClient has methods for each endpoints. Namely,

  • arrivals: Arrival information for a given station(s) or stop(s).
  • follow: Follow specific train by runnumber.
  • locations: Get all trains for a given route(s).

More endpoint specific documentation found here

This API requires a key which can be easily received here. Follow the .env.example file for setting.

Installation

This package is available on pip. Install with:

$ pip install python-cta

Getting Started

from cta import CTAClient
damen_blue_line_mapid = 40590

# Get arrival information for damen blue line station.
cta_client = CTAClient()
arrival_response = cta_client.arrivals(mapid=damen_blue_line_mapid)
df_arrivals = arrival_response.to_frame()
print(df_arrivals)

# Follow specific train
runnumber = df_arrivals["rn"].tolist()[0]
follow_response = cta_client.follow(runnumber=runnumber)
df_follow = follow_response.to_frame()
print(df_follow)
from cta import Route

# Get the location of all Blue Line trains.
location_response = cta_client.locations(Route.BLUE)
df_locations = location_response.to_frame()
print(df_locations)

# Or all trains on the track
location_response = cta_client.locations(route=[route for route in Route])
df_locations = location_response.to_frame()
print(df_locations)

Information about the stations can be found with the Stations class. Below is an example to find the mapid for Damen blue line.

from cta import Stations

stations = Stations()
df_stations = stations.data
print(df_stations)

df_damen = stations.lookup("Damen", route=Route.BLUE)
print(df_damen)

Try this example for yourself in scripts/readme_example.py

Notes

This currently doesn't support the CTA bus API endpoints. However, it might in the future.

cta's People

Contributors

wd60622 avatar

Stargazers

 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.