Module for the v0 version of the SPTrans API.
The first thing you have to do, in order to use it, is to instantiate a client and authenticate to the API:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
Then you can use the other methods to grab data from the API.
Bases: exceptions.Exception
Raised when the authentication fails - for example, with a wrong token -.
Bases: object
Main client class.
Warning
Any method (except authenticate()) may raise RequestError if the client is not authenticated anymore. So keep an eye on the authentication state.
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
Authenticates to the webservice.
Parameters: | token (str) – The API token string. |
---|---|
Raises : | AuthenticationError when there’s an error during authentication. |
Gets the arrival forecast, provided a route code or a stop code or both.
You must provide at least one of the parameters. If you provide only a stop_code, it will return a forecast for all routes that attend a certain stop. If you provide only a route_code, it will return a forecast for all stops that a certain route attends to. If you provide both, it will return a forecast for the specific route attending to the specific stop provided.
Parameters: |
|
---|---|
Returns: | A single ForecastWithStop object, when passing only stop_code or both. |
Returns: | A single ForecastWithStops object, when passing only route_code. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
forecast = client.get_forecast(stop_code=1234)
for route in forecast.stop.routes:
for vehicle in route.vehicles:
print(vehicle.prefix)
forecast = client.get_forecast(stop_code=1234, route_code=2345)
for route in forecast.stop.routes:
for vehicle in route.vehicles:
print(vehicle.prefix)
forecast = client.get_forecast(route_code=2345)
for stop in forecast.stops:
for vehicle in stop.vehicles:
print(vehicle.prefix)
Gets the vehicles with their current positions, provided a route code.
Parameters: | code (int) – The route code to use for matching. |
---|---|
Returns: | A single Positions object. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
positions = client.get_positions(1234)
print(positions.time)
for vehicle in positions.vehicles:
print(vehicle.prefix)
Lists all the bus lanes in the city.
Returns: | A generator that yields Lane objects. |
---|
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
for lane in client.list_lanes():
print(lane.code, lane.name)
Searches for routes that match the provided keywords.
Parameters: | keywords (str) – The keywords, in a single string, to use for matching. |
---|---|
Returns: | A generator that yields Route objects. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
for route in client.search_routes('butanta'):
print(route.code, route.sign)
Searches for bus stops that match the provided keywords.
Parameters: | keywords (str) – The keywords, in a single string, to use for matching. |
---|---|
Returns: | A generator that yields Stop objects. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
for stop in client.search_stops('butanta'):
print(stop.code, stop.name)
Searches for bus stops that are contained in a lane specified by its code.
Parameters: | code (int) – The lane code to use for matching. |
---|---|
Returns: | A generator that yields Stop objects. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
for stop in client.search_stops_by_lane(1234):
print(stop.code, stop.name)
Searches for bus stops that are passed by the route specified by its code.
Parameters: | code (int) – The route code to use for matching. |
---|---|
Returns: | A generator that yields Stop objects. |
Example:
from sptrans.v0 import Client
client = Client()
client.authenticate('this is my token')
for stop in client.search_stops_by_route(1234):
print(stop.code, stop.name)
Bases: sptrans.v0.ForecastWithStop, sptrans.v0.TupleMapMixin
A namedtuple representing a bus stop forecast with routes and the time when the information was retrieved.
Variables: |
|
---|
Bases: sptrans.v0.ForecastWithStops, sptrans.v0.TupleMapMixin
A namedtuple representing a list of bus stops forecast with vehicles and the time when the information was retrieved.
Variables: |
|
---|
Bases: sptrans.v0.Lane, sptrans.v0.TupleMapMixin
A namedtuple representing a bus lane.
Variables: |
|
---|
Bases: sptrans.v0.Positions, sptrans.v0.TupleMapMixin
A namedtuple representing a sequence of vehicles positions, with the time when the information was retrieved.
Variables: |
|
---|
Bases: exceptions.Exception
Raised when the request failes to be accomplished.
Normally this is due to the client not being authenticated anymore. In this case, just authenticate again, and it should be back at work.
Bases: sptrans.v0.Route, sptrans.v0.TupleMapMixin
A namedtuple representing a route.
Variables: |
|
---|
Bases: sptrans.v0.RouteWithVehicles, sptrans.v0.TupleMapMixin
A namedtuple representing a route with a sequence of vehicles with their current positions.
Variables: |
|
---|
Bases: sptrans.v0.Stop, sptrans.v0.TupleMapMixin
A namedtuple representing a bus stop.
Variables: |
|
---|
Bases: sptrans.v0.StopWithRoutes, sptrans.v0.TupleMapMixin
A namedtuple representing a bus stop with a list of routes that pass through this stop.
Variables: |
|
---|
Bases: sptrans.v0.StopWithVehicles, sptrans.v0.TupleMapMixin
A namedtuple representing a bus stop with a list of vehicles that pass through this stop.
Variables: |
|
---|
Bases: sptrans.v0.Vehicle, sptrans.v0.TupleMapMixin
A namedtuple representing a vehicle (bus) with its position.
Variables: |
|
---|
Bases: sptrans.v0.VehicleForecast, sptrans.v0.TupleMapMixin
A namedtuple representing a vehicle (bus) with its position and forecast to arrive at a certain stop.
Variables: |
|
---|