Package tflwrapper
Sub-modules
tflwrapper.tfl
Classes
class accidentStats (app_key)
-
Expand source code
class accidentStats(tflAPI): """Accident from Unified API""" def getAllByYear(self, year: int): """ Gets all accident details for accidents occuring in the specified year Args: year: The year for which to filter the accidents on. """ return super(accidentStats, self).sendRequestUnified( f"/AccidentStats/{year}" )
Accident from Unified API
Ancestors
Methods
def getAllByYear(self, year: int)
-
Expand source code
def getAllByYear(self, year: int): """ Gets all accident details for accidents occuring in the specified year Args: year: The year for which to filter the accidents on. """ return super(accidentStats, self).sendRequestUnified( f"/AccidentStats/{year}" )
Gets all accident details for accidents occuring in the specified year
Args
year
- The year for which to filter the accidents on.
Inherited members
class airQuality (app_key)
-
Expand source code
class airQuality(tflAPI): """Air Quality from the TFL Unified API""" def getAirQuality(self): """ Get all current and future air quality forecast """ return super(airQuality, self).sendRequestUnified( f"/AirQuality" )
Air Quality from the TFL Unified API
Ancestors
Methods
def getAirQuality(self)
-
Expand source code
def getAirQuality(self): """ Get all current and future air quality forecast """ return super(airQuality, self).sendRequestUnified( f"/AirQuality" )
Get all current and future air quality forecast
Inherited members
class bikePoint (app_key)
-
Expand source code
class bikePoint(tflAPI): """Bike point from Unified API""" def getAll(self): """Gets all bike point locations""" return super(bikePoint, self).sendRequestUnified( "/BikePoint" ) def getByID(self, ID): """ Gets the bike point by the given id Args: ID: The ID of the bike point """ return super(bikePoint, self).sendRequestUnified( f"/BikePoint/{ID}" ) def getByName(self, name): """ Search for bike points by their name Args: name: The name of the bike point """ return super(bikePoint, self).sendRequestUnified( f"/BikePoint/Search", {'query': name} )
Bike point from Unified API
Ancestors
Methods
def getAll(self)
-
Expand source code
def getAll(self): """Gets all bike point locations""" return super(bikePoint, self).sendRequestUnified( "/BikePoint" )
Gets all bike point locations
def getByID(self, ID)
-
Expand source code
def getByID(self, ID): """ Gets the bike point by the given id Args: ID: The ID of the bike point """ return super(bikePoint, self).sendRequestUnified( f"/BikePoint/{ID}" )
Gets the bike point by the given id
Args
ID
- The ID of the bike point
def getByName(self, name)
-
Expand source code
def getByName(self, name): """ Search for bike points by their name Args: name: The name of the bike point """ return super(bikePoint, self).sendRequestUnified( f"/BikePoint/Search", {'query': name} )
Search for bike points by their name
Args
name
- The name of the bike point
Inherited members
class crowding (app_key)
-
Expand source code
class crowding(tflAPI): """Crowding from Unified API""" def getAllByNaptan(self, id): """ Get crowding information for Naptan Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}" ) def getByNaptanDay(self, id, day): """ Get crowding information for Naptan for a specified day of week Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) day: The day of which you would like data to return (eg. MON, TUE) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}/{day}" ) def getLiveByNaptan(self, id): """ Get crowding information for Naptan for a specified day of week Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}/Live" )
Crowding from Unified API
Ancestors
Methods
def getAllByNaptan(self, id)
-
Expand source code
def getAllByNaptan(self, id): """ Get crowding information for Naptan Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}" )
Get crowding information for Naptan
Args
id
- NaPTAN ID of the stop (eg. 940GZZLUASL)
def getByNaptanDay(self, id, day)
-
Expand source code
def getByNaptanDay(self, id, day): """ Get crowding information for Naptan for a specified day of week Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) day: The day of which you would like data to return (eg. MON, TUE) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}/{day}" )
Get crowding information for Naptan for a specified day of week
Args
id
- NaPTAN ID of the stop (eg. 940GZZLUASL)
day
- The day of which you would like data to return (eg. MON, TUE)
def getLiveByNaptan(self, id)
-
Expand source code
def getLiveByNaptan(self, id): """ Get crowding information for Naptan for a specified day of week Args: id: NaPTAN ID of the stop (eg. 940GZZLUASL) """ return super(crowding, self).sendRequestUnified( f"/Crowding/{id}/Live" )
Get crowding information for Naptan for a specified day of week
Args
id
- NaPTAN ID of the stop (eg. 940GZZLUASL)
Inherited members
class disruptions (app_key)
-
Expand source code
class disruptions(tflAPI): """Disruptions from Unified API""" def getAllLifts(self): """ List of all currently disrupted lift routes, refreshed every 1 minute """ return super(disruptions, self).sendRequestUnified( f"/Disruptions/Lifts" )
Disruptions from Unified API
Ancestors
Methods
def getAllLifts(self)
-
Expand source code
def getAllLifts(self): """ List of all currently disrupted lift routes, refreshed every 1 minute """ return super(disruptions, self).sendRequestUnified( f"/Disruptions/Lifts" )
List of all currently disrupted lift routes, refreshed every 1 minute
Inherited members
class line (app_key)
-
Expand source code
class line(tflAPI): """Line from Unified API""" def getModes(self): """Gets a list of valid modes""" return super(line, self).sendRequestUnified( "/Line/Meta/Modes" ) def getSeverityCodes(self): """Gets a list of valid severity codes""" return super(line, self).sendRequestUnified( "/Line/Meta/Severity" ) def getDisruptionCategories(self): """Gets a list of valid disruption categories""" return super(line, self).sendRequestUnified( "/Line/Meta/DisruptionCatergories" ) def getServiceTypes(self): """Gets a list of valid service types""" return super(line, self).sendRequestUnified( "/Line/Meta/ServiceTypes" ) def getAllStopPoints(self, _line): """ Gets a list of the stations that serve the given line id Args: line: The line id e.g. victoria, circle, N133 """ return super(line, self).sendRequestUnified( F"/Line/{_line}/StopPoints" ) def getAllByModes(self, modes): """ Gets lines that serve the given modes Args: modes: A list of modes e.g. tube, tram """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(modes)}" ) def getStatusByLine(self, lines, detail = False, startDate = None, endDate = None): """ Gets the line status of for given line ids e.g Minor Delays Args: lines: A list of line ids e.g. ['victoria', 'circle'] detail: Include details of the disruptions that are causing the line status including the affected stops and routes """ if startDate == None or endDate == None: return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lines)}/Status", {'detail': detail } ) else: return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lines)}/Status/{self.getRFC3339(startDate)}/to/{self.getRFC3339(endDate)}", {'detail': detail } ) def getStatusByModes(self, modes, detail = False, severityLevel = ""): """ Gets the line status of for all lines for the given modes Args: modes: A list of modes e.g. tube, tram detail: Include details of the disruptions that are causing the line status including the affected stops and routes severityLevel: A list of severity codes to filter on. Supported values: Minor, Major, Severe """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(modes)}/Status", {'detail': detail, 'severityLevel': severityLevel } ) def getTimetableFromTo(self, _line, _from, _to): """ Gets the timetable for a specified station on the give line with specified destination Args: _line: The line id e.g. victoria, circle, N133 _from: The station id e.g. 940GZZLUASL _to: The destination station id e.g. 940GZZLUASL """ return super(line, self).sendRequestUnified( f"/Line/{_line}/Timetable/{_from}/to/{_to}" ) def getTimetableFromStation(self, _line, NaPTANID, direction): """ Gets the inbound timetable for a specified station on the give line Args: _line: The line id e.g. victoria, circle, N133 NaPTANID: The station id e.g. 940GZZLUASL direction: The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'outbound' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{_line}/Timetable/{NaPTANID}", {'direction': direction} ) def getArrivalsByNaptan(self, lineids, naptan, destinationStationId, direction = "all"): """ Gets the arrivals for a given station on the give line Args: lineids: A list of line ids e.g. ['victoria', 'circle'] naptan: The station id e.g. 940GZZLUASL destinationStationId: The destination station id e.g. 940GZZLUASL direction: The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'all' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lineids)}/Arrivals/{naptan}", {'direction': direction, 'destinationStationId': destinationStationId } ) def getAllValidRoutes(self, serviceTypes): """ Get all valid routes for all lines, including the name and id of the originating and terminating stops for each route. Args: serviceTypes: A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified """ return super(line, self).sendRequestUnified( f"/Line/Route", { 'serviceTypes': serviceTypes} ) def getStatusByID(self, lineids, detail: bool): """ Gets the line status of for all lines for the given modes Args: lineids: A list of line ids e.g. ['victoria', 'circle'] detail: Include details of the disruptions that are causing the line status including the affected stops and routes """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(lineids)}/Status", {'detail': detail} ) def getRouteByIDs(self, lineids, serviceTypes): """ Get all valid routes for given line ids, including the name and id of the originating and terminating stops for each route Args: lineids: A list of line ids e.g. ['victoria', 'circle'] serviceTypes: A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lineids)}/Route", { 'serviceTypes': serviceTypes} )
Line from Unified API
Ancestors
Methods
def getAllByModes(self, modes)
-
Expand source code
def getAllByModes(self, modes): """ Gets lines that serve the given modes Args: modes: A list of modes e.g. tube, tram """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(modes)}" )
Gets lines that serve the given modes
Args
modes
- A list of modes e.g. tube, tram
def getAllStopPoints(self, _line)
-
Expand source code
def getAllStopPoints(self, _line): """ Gets a list of the stations that serve the given line id Args: line: The line id e.g. victoria, circle, N133 """ return super(line, self).sendRequestUnified( F"/Line/{_line}/StopPoints" )
Gets a list of the stations that serve the given line id
Args
line
- The line id e.g. victoria, circle, N133
def getAllValidRoutes(self, serviceTypes)
-
Expand source code
def getAllValidRoutes(self, serviceTypes): """ Get all valid routes for all lines, including the name and id of the originating and terminating stops for each route. Args: serviceTypes: A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified """ return super(line, self).sendRequestUnified( f"/Line/Route", { 'serviceTypes': serviceTypes} )
Get all valid routes for all lines, including the name and id of the originating and terminating stops for each route.
Args
serviceTypes
- A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified
def getArrivalsByNaptan(self, lineids, naptan, destinationStationId, direction='all')
-
Expand source code
def getArrivalsByNaptan(self, lineids, naptan, destinationStationId, direction = "all"): """ Gets the arrivals for a given station on the give line Args: lineids: A list of line ids e.g. ['victoria', 'circle'] naptan: The station id e.g. 940GZZLUASL destinationStationId: The destination station id e.g. 940GZZLUASL direction: The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'all' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lineids)}/Arrivals/{naptan}", {'direction': direction, 'destinationStationId': destinationStationId } )
Gets the arrivals for a given station on the give line
Args
lineids
- A list of line ids e.g. ['victoria', 'circle']
naptan
- The station id e.g. 940GZZLUASL
destinationStationId
- The destination station id e.g. 940GZZLUASL
direction
- The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'all' if not specified
def getDisruptionCategories(self)
-
Expand source code
def getDisruptionCategories(self): """Gets a list of valid disruption categories""" return super(line, self).sendRequestUnified( "/Line/Meta/DisruptionCatergories" )
Gets a list of valid disruption categories
def getModes(self)
-
Expand source code
def getModes(self): """Gets a list of valid modes""" return super(line, self).sendRequestUnified( "/Line/Meta/Modes" )
Gets a list of valid modes
def getRouteByIDs(self, lineids, serviceTypes)
-
Expand source code
def getRouteByIDs(self, lineids, serviceTypes): """ Get all valid routes for given line ids, including the name and id of the originating and terminating stops for each route Args: lineids: A list of line ids e.g. ['victoria', 'circle'] serviceTypes: A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lineids)}/Route", { 'serviceTypes': serviceTypes} )
Get all valid routes for given line ids, including the name and id of the originating and terminating stops for each route
Args
lineids
- A list of line ids e.g. ['victoria', 'circle']
serviceTypes
- A list of service types e.g. 'tube, 'tram'. Supported values: Regular, Night. Defaulted to 'Regular' if not specified
def getServiceTypes(self)
-
Expand source code
def getServiceTypes(self): """Gets a list of valid service types""" return super(line, self).sendRequestUnified( "/Line/Meta/ServiceTypes" )
Gets a list of valid service types
def getSeverityCodes(self)
-
Expand source code
def getSeverityCodes(self): """Gets a list of valid severity codes""" return super(line, self).sendRequestUnified( "/Line/Meta/Severity" )
Gets a list of valid severity codes
def getStatusByID(self, lineids, detail: bool)
-
Expand source code
def getStatusByID(self, lineids, detail: bool): """ Gets the line status of for all lines for the given modes Args: lineids: A list of line ids e.g. ['victoria', 'circle'] detail: Include details of the disruptions that are causing the line status including the affected stops and routes """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(lineids)}/Status", {'detail': detail} )
Gets the line status of for all lines for the given modes
Args
lineids
- A list of line ids e.g. ['victoria', 'circle']
detail
- Include details of the disruptions that are causing the line status including the affected stops and routes
def getStatusByLine(self, lines, detail=False, startDate=None, endDate=None)
-
Expand source code
def getStatusByLine(self, lines, detail = False, startDate = None, endDate = None): """ Gets the line status of for given line ids e.g Minor Delays Args: lines: A list of line ids e.g. ['victoria', 'circle'] detail: Include details of the disruptions that are causing the line status including the affected stops and routes """ if startDate == None or endDate == None: return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lines)}/Status", {'detail': detail } ) else: return super(line, self).sendRequestUnified( f"/Line/{self.arrayToCSV(lines)}/Status/{self.getRFC3339(startDate)}/to/{self.getRFC3339(endDate)}", {'detail': detail } )
Gets the line status of for given line ids e.g Minor Delays
Args
lines
- A list of line ids e.g. ['victoria', 'circle']
detail
- Include details of the disruptions that are causing the line status including the affected stops and routes
def getStatusByModes(self, modes, detail=False, severityLevel='')
-
Expand source code
def getStatusByModes(self, modes, detail = False, severityLevel = ""): """ Gets the line status of for all lines for the given modes Args: modes: A list of modes e.g. tube, tram detail: Include details of the disruptions that are causing the line status including the affected stops and routes severityLevel: A list of severity codes to filter on. Supported values: Minor, Major, Severe """ return super(line, self).sendRequestUnified( f"/Line/Mode/{self.arrayToCSV(modes)}/Status", {'detail': detail, 'severityLevel': severityLevel } )
Gets the line status of for all lines for the given modes
Args
modes
- A list of modes e.g. tube, tram
detail
- Include details of the disruptions that are causing the line status including the affected stops and routes
severityLevel
- A list of severity codes to filter on. Supported values: Minor, Major, Severe
def getTimetableFromStation(self, _line, NaPTANID, direction)
-
Expand source code
def getTimetableFromStation(self, _line, NaPTANID, direction): """ Gets the inbound timetable for a specified station on the give line Args: _line: The line id e.g. victoria, circle, N133 NaPTANID: The station id e.g. 940GZZLUASL direction: The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'outbound' if not specified """ return super(line, self).sendRequestUnified( f"/Line/{_line}/Timetable/{NaPTANID}", {'direction': direction} )
Gets the inbound timetable for a specified station on the give line
Args
_line
- The line id e.g. victoria, circle, N133
NaPTANID
- The station id e.g. 940GZZLUASL
direction
- The direction of the timetable. Supported values: inbound, outbound. Defaulted to 'outbound' if not specified
def getTimetableFromTo(self, _line, _from, _to)
-
Expand source code
def getTimetableFromTo(self, _line, _from, _to): """ Gets the timetable for a specified station on the give line with specified destination Args: _line: The line id e.g. victoria, circle, N133 _from: The station id e.g. 940GZZLUASL _to: The destination station id e.g. 940GZZLUASL """ return super(line, self).sendRequestUnified( f"/Line/{_line}/Timetable/{_from}/to/{_to}" )
Gets the timetable for a specified station on the give line with specified destination
Args
_line
- The line id e.g. victoria, circle, N133
_from
- The station id e.g. 940GZZLUASL
_to
- The destination station id e.g. 940GZZLUASL
Inherited members
class mode (app_key)
-
Expand source code
class mode(tflAPI): """Mode API, /mode""" def getActiveServiceTypes(self): """Returns the service type active for a mode, currently only supports tube""" return super(mode, self).sendRequestUnified( "/Mode/ActiveServiceTypes" ) def getAllArrivalPredictions(self, modes: str, count: str): """ Returns arrival predictions for all stops Args: modes: The modes for which to return predictions e.g. tube, dlr count: The number of predictions to return, -1 to return all available """ return super(mode, self).sendRequestUnified( f"/Mode/{modes}/Arrivals", {'count': count} )
Mode API, /mode
Ancestors
Methods
def getActiveServiceTypes(self)
-
Expand source code
def getActiveServiceTypes(self): """Returns the service type active for a mode, currently only supports tube""" return super(mode, self).sendRequestUnified( "/Mode/ActiveServiceTypes" )
Returns the service type active for a mode, currently only supports tube
def getAllArrivalPredictions(self, modes: str, count: str)
-
Expand source code
def getAllArrivalPredictions(self, modes: str, count: str): """ Returns arrival predictions for all stops Args: modes: The modes for which to return predictions e.g. tube, dlr count: The number of predictions to return, -1 to return all available """ return super(mode, self).sendRequestUnified( f"/Mode/{modes}/Arrivals", {'count': count} )
Returns arrival predictions for all stops
Args
modes
- The modes for which to return predictions e.g. tube, dlr
count
- The number of predictions to return, -1 to return all available
Inherited members
class occupancy (app_key)
-
Expand source code
class occupancy(tflAPI): """Occupancy from Unified API""" def getBikePointByIDs(self, ids): """ Gets the occupancy data for bike points Args: ids: List of bike point IDs (Eg. ['BikePoints_208', 'BikePoints_209']) """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/BikePoints/{self.arrayToCSV(ids)}" ) def getCarParkByID(self, id): """ Gets the occupancy for a car park with a given id Args: id: Car park ID (Eg. 'CarParks_800468') """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/CarPark/{id}" ) def getChargeConnectorByID(self, id): """ Gets the occupancy for a charge connectors with a given id Args: id: Charge connector ID (Eg. 'ChargePointESB-UT06NW-1') """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/ChargeConnector/{id}" ) def getAllCarParks(self): """Gets the occupancy for all car parks that have occupancy data""" return super(occupancy, self).sendRequestUnified( f"/Occupancy/CarPark" ) def getAllChargeConnectors(self): """Gets the occupancy for all charge connectors""" return super(occupancy, self).sendRequestUnified( f"/Occupancy/ChargeConnector" )
Occupancy from Unified API
Ancestors
Methods
def getAllCarParks(self)
-
Expand source code
def getAllCarParks(self): """Gets the occupancy for all car parks that have occupancy data""" return super(occupancy, self).sendRequestUnified( f"/Occupancy/CarPark" )
Gets the occupancy for all car parks that have occupancy data
def getAllChargeConnectors(self)
-
Expand source code
def getAllChargeConnectors(self): """Gets the occupancy for all charge connectors""" return super(occupancy, self).sendRequestUnified( f"/Occupancy/ChargeConnector" )
Gets the occupancy for all charge connectors
def getBikePointByIDs(self, ids)
-
Expand source code
def getBikePointByIDs(self, ids): """ Gets the occupancy data for bike points Args: ids: List of bike point IDs (Eg. ['BikePoints_208', 'BikePoints_209']) """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/BikePoints/{self.arrayToCSV(ids)}" )
Gets the occupancy data for bike points
Args
ids
- List of bike point IDs (Eg. ['BikePoints_208', 'BikePoints_209'])
def getCarParkByID(self, id)
-
Expand source code
def getCarParkByID(self, id): """ Gets the occupancy for a car park with a given id Args: id: Car park ID (Eg. 'CarParks_800468') """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/CarPark/{id}" )
Gets the occupancy for a car park with a given id
Args
id
- Car park ID (Eg. 'CarParks_800468')
def getChargeConnectorByID(self, id)
-
Expand source code
def getChargeConnectorByID(self, id): """ Gets the occupancy for a charge connectors with a given id Args: id: Charge connector ID (Eg. 'ChargePointESB-UT06NW-1') """ return super(occupancy, self).sendRequestUnified( f"/Occupancy/ChargeConnector/{id}" )
Gets the occupancy for a charge connectors with a given id
Args
id
- Charge connector ID (Eg. 'ChargePointESB-UT06NW-1')
Inherited members
class road (app_key)
-
Expand source code
class road(tflAPI): """Road from Unified API""" def getCategories(self): """Gets a list of valid RoadDisruption categories""" return super(road, self).sendRequestUnified( '/Road/Meta/Categories', {} ) def getSeverities(self): """Gets a list of valid RoadDisruption severity codes""" return super(road, self).sendRequestUnified( '/Road/Meta/Severities', {} ) def getAll(self): """Get all roads managed by TfL""" return super(road, self).sendRequestUnified( '/Road' ) def getByID(self, ids): """ Get the road with the specified ID (Eg. A1) Args: ids: ID(s) of the road(s). Eg. ['A1'] """ return super(road, self).sendRequestUnified( f'/Road/{self.arrayToCSV(ids)}' ) def getStatusByID(self, ids, startDate, endDate): """ Gets the specified roads with the status aggregated over the date range specified, or now until the end of today if no dates are passed. Args: ids: ID(s) of the road(s). Eg. ['A1'] startDate: Optional, the start time to filter on endDate: Optional, the end time to filter on """ return super(road, self).sendRequestUnified( f'/Road/{self.arrayToCSV(ids)}', {'startDate': self.getRFC3339( startDate), 'endDate': self.getRFC3339(endDate)} ) def getAllStreetDisruption(self, startDate, endDate): """ Gets a list of disrupted streets Args: startDate: Optional, the start time to filter on endDate: Optional, the end time to filter on """ return super(road, self).sendRequestUnified( '/Road/all/Street/Disruption', {'startDate': self.getRFC3339( startDate), 'endDate': self.getRFC3339(endDate)} ) def getAllDisruptionsByID(self, ids, stripContent: bool = False): """ Gets a list of disrupted streets Args: ids: ID(s) of the road(s). Eg. ['A1'] stripContent: Optional, if true, the content of the disruption will be stripped from the response """ return super(road, self).sendRequestUnified( f'/Road/all/Disruption/{self.arrayToCSV(ids)}', {'stripContent': stripContent} )
Road from Unified API
Ancestors
Methods
def getAll(self)
-
Expand source code
def getAll(self): """Get all roads managed by TfL""" return super(road, self).sendRequestUnified( '/Road' )
Get all roads managed by TfL
def getAllDisruptionsByID(self, ids, stripContent: bool = False)
-
Expand source code
def getAllDisruptionsByID(self, ids, stripContent: bool = False): """ Gets a list of disrupted streets Args: ids: ID(s) of the road(s). Eg. ['A1'] stripContent: Optional, if true, the content of the disruption will be stripped from the response """ return super(road, self).sendRequestUnified( f'/Road/all/Disruption/{self.arrayToCSV(ids)}', {'stripContent': stripContent} )
Gets a list of disrupted streets
Args
ids
- ID(s) of the road(s). Eg. ['A1']
stripContent
- Optional, if true, the content of the disruption will be stripped from the response
def getAllStreetDisruption(self, startDate, endDate)
-
Expand source code
def getAllStreetDisruption(self, startDate, endDate): """ Gets a list of disrupted streets Args: startDate: Optional, the start time to filter on endDate: Optional, the end time to filter on """ return super(road, self).sendRequestUnified( '/Road/all/Street/Disruption', {'startDate': self.getRFC3339( startDate), 'endDate': self.getRFC3339(endDate)} )
Gets a list of disrupted streets
Args
startDate
- Optional, the start time to filter on
endDate
- Optional, the end time to filter on
def getByID(self, ids)
-
Expand source code
def getByID(self, ids): """ Get the road with the specified ID (Eg. A1) Args: ids: ID(s) of the road(s). Eg. ['A1'] """ return super(road, self).sendRequestUnified( f'/Road/{self.arrayToCSV(ids)}' )
Get the road with the specified ID (Eg. A1)
Args
ids
- ID(s) of the road(s). Eg. ['A1']
def getCategories(self)
-
Expand source code
def getCategories(self): """Gets a list of valid RoadDisruption categories""" return super(road, self).sendRequestUnified( '/Road/Meta/Categories', {} )
Gets a list of valid RoadDisruption categories
def getSeverities(self)
-
Expand source code
def getSeverities(self): """Gets a list of valid RoadDisruption severity codes""" return super(road, self).sendRequestUnified( '/Road/Meta/Severities', {} )
Gets a list of valid RoadDisruption severity codes
def getStatusByID(self, ids, startDate, endDate)
-
Expand source code
def getStatusByID(self, ids, startDate, endDate): """ Gets the specified roads with the status aggregated over the date range specified, or now until the end of today if no dates are passed. Args: ids: ID(s) of the road(s). Eg. ['A1'] startDate: Optional, the start time to filter on endDate: Optional, the end time to filter on """ return super(road, self).sendRequestUnified( f'/Road/{self.arrayToCSV(ids)}', {'startDate': self.getRFC3339( startDate), 'endDate': self.getRFC3339(endDate)} )
Gets the specified roads with the status aggregated over the date range specified, or now until the end of today if no dates are passed.
Args
ids
- ID(s) of the road(s). Eg. ['A1']
startDate
- Optional, the start time to filter on
endDate
- Optional, the end time to filter on
Inherited members
class stopPoint (app_key)
-
Expand source code
class stopPoint(tflAPI): """Stop Point from Unified API""" def getCategories(self): """Gets the list of available StopPoint additional information categories""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/Categories" ) def getTypes(self): """Gets the list of available StopPoint types""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/StopTypes" ) def getModes(self): """Gets the list of available StopPoint modes""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/Modes" ) def getByIDs(self, ids, includeCrowdingData: bool): """ Gets a list of StopPoints corresponding to the given list of stop ids Args: ids: A list of StopPoint ids (station naptan code e.g. 940GZZLUAS) includeCrowdingData: Specify true to return crowding data (static) for each stop point """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{','.join(ids)}", {'includeCrowdingData': includeCrowdingData} ) def getAllByStopType(self, array): """ Gets all stop points of a given type Args: array: An array of stop point types e.g. ['NaptanPublicBusCoachTram'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{super(stopPoint, self).arrayToCSV(array)}" ) def getServiceTypesByID(self, stopPointID: str, lineIds, modes): """ Gets the service types for a given Stop Point Args: stopPointID: A StopPoint id (station naptan code e.g. 940GZZLUAS) lineIds: A list of Line ids (e.g. victoria) modes: An array of modes e.g. ['tube', 'dlr'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/ServiceTypes", {"id": stopPointID, "lineIds": lineIds, "modes": modes}, ) def search(self, name: str, modes): """ Search StopPoints by their common name. Will not return a valid NaPTAN for HUB Args: name: The name of station to search for modes: An array of modes e.g. ['tube', 'dlr'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Search/${name}", {"modes": super(stopPoint, self).arrayToCSV(modes)}, ) def getStationArrivals(self, naptanID: str): """ Get all service arrivals Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/Arrivals" ) # def getArrivalsDepartures(self, naptanID: str, lineIds): # """ # Get all service arrivals and departures # :param naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) # :param lineIds: List of line ids e.g. ['tflwrapper-rail', 'london-overground', 'thameslink'] # """ # return super(stopPoint, self).sendRequestUnified( # f"StopPoint/${naptanID}/ArrivalsDepartures", {'lineIds': lineIds} # ) def getDisruptionsByID( self, ids, getFamily: bool, includeRouteBlockedStops: bool, flattenResponse: bool, ): """ Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have Args: ids: A list of StopPoint ids (station naptan code e.g. 940GZZLUAS) getFamily: Specify true to return disruptions for entire family, or false to return disruptions for just this stop point. Defaults to false. includeRouteBlockedStops: Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false. flattenResponse: Specify true to return a flattened response, or false to return a nested response. Defaults to false. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{super(stopPoint, self).arrayToCSV(ids)}/Disruption", {'getFamily': getFamily, 'includeRouteBlockedStops': includeRouteBlockedStops, 'flattenResponse': flattenResponse}, ) def getDisruptionsByMode(self, modes, includeRouteBlockedStops: bool): """ Gets a distinct list of disrupted stop points for the given modes Args: modes: An array of modes e.g. ['tube', 'dlr'] includeRouteBlockedStops: Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Mode/{super(stopPoint, self).arrayToCSV(modes)}/Disruption", {'includeRouteBlockedStops': includeRouteBlockedStops}, ) def getReachableStationsByID(self, naptanID: str, lineID: str, serviceTypes=None): """ Gets Stop points that are reachable from a station/line combination Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) lineID: A Line id (e.g. victoria) serviceTypes: An array of service types. Supported values: Regular, Night. Defaults to Regular. """ if serviceTypes is None: serviceTypes = ["Regular"] return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/CanReachOnLine/{lineID}", {"serviceTypes": super(stopPoint, self).arrayToCSV(serviceTypes)}, ) def getRouteSectionByID(self, naptanID: str, serviceTypes): """ Get the route sections for all the lines that service the given stop point id# Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) serviceTypes: An array of service types. Supported values: Regular, Night. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/Route", {"serviceTypes": super(stopPoint, self).arrayToCSV(serviceTypes)}, ) def getInRadius( self, stopTypes, radius: int, useStopPointHierarchy: bool, modes, categories, returnLines: bool, latitude: int, longitude: int, ): """ Gets a list of StopPoints within {radius} by the specified criteria Args: stopTypes: An array of stop point types e.g. ['NaptanPublicBusCoachTram'] radius: The radius in metres. Defaults to 200. useStopPointHierarchy: Specify true to return stop points in the hierarchy, or false to return stop points at the specified radius. Defaults to false. modes: An array of modes e.g. ['tube', 'dlr'] categories: An array of categories e.g. ['tram', 'bus'] returnLines: Specify true to return the lines that service the stop point, or false to return the stop point itself. Defaults to false. latitude: The latitude of the location to search from. longitude: The longitude of the location to search from. """ return super(stopPoint, self).sendRequestUnified( "/StopPoint", { "stopTypes": super(stopPoint, self).arrayToCSV(stopTypes), "radius": radius, "useStopPointHierarchy": useStopPointHierarchy, "modes": super(stopPoint, self).arrayToCSV(modes), "categories": super(stopPoint, self).arrayToCSV(categories), "returnLines": returnLines, "latitude": latitude, "longitude": longitude, }, ) def getBySMSCode(self, smsID: str, output: str): """ Gets a StopPoint for a given sms code Args: smsID: A 5-digit sms code e.g. 73241, 50435, 5633. output: If set to "web", a 302 redirect to relevant website bus stop page is returned. All other values are ignored. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Sms/{smsID}", {'output': output} ) def getTaxiRanksByID(self, naptanID: str): """ Gets a list of taxi ranks corresponding to the given stop point id Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/TaxiRanks" ) def getCarParksByID(self, naptanID: str): """ Get car parks corresponding to the given stop point id Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/CarParks" )
Stop Point from Unified API
Ancestors
Methods
def getAllByStopType(self, array)
-
Expand source code
def getAllByStopType(self, array): """ Gets all stop points of a given type Args: array: An array of stop point types e.g. ['NaptanPublicBusCoachTram'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{super(stopPoint, self).arrayToCSV(array)}" )
Gets all stop points of a given type
Args
array
- An array of stop point types e.g. ['NaptanPublicBusCoachTram']
def getByIDs(self, ids, includeCrowdingData: bool)
-
Expand source code
def getByIDs(self, ids, includeCrowdingData: bool): """ Gets a list of StopPoints corresponding to the given list of stop ids Args: ids: A list of StopPoint ids (station naptan code e.g. 940GZZLUAS) includeCrowdingData: Specify true to return crowding data (static) for each stop point """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{','.join(ids)}", {'includeCrowdingData': includeCrowdingData} )
Gets a list of StopPoints corresponding to the given list of stop ids
Args
ids
- A list of StopPoint ids (station naptan code e.g. 940GZZLUAS)
includeCrowdingData
- Specify true to return crowding data (static) for each stop point
def getBySMSCode(self, smsID: str, output: str)
-
Expand source code
def getBySMSCode(self, smsID: str, output: str): """ Gets a StopPoint for a given sms code Args: smsID: A 5-digit sms code e.g. 73241, 50435, 5633. output: If set to "web", a 302 redirect to relevant website bus stop page is returned. All other values are ignored. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Sms/{smsID}", {'output': output} )
Gets a StopPoint for a given sms code
Args
smsID
- A 5-digit sms code e.g. 73241, 50435, 5633.
output
- If set to "web", a 302 redirect to relevant website bus stop page is returned. All other values are ignored.
def getCarParksByID(self, naptanID: str)
-
Expand source code
def getCarParksByID(self, naptanID: str): """ Get car parks corresponding to the given stop point id Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/CarParks" )
Get car parks corresponding to the given stop point id
Args
naptanID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
def getCategories(self)
-
Expand source code
def getCategories(self): """Gets the list of available StopPoint additional information categories""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/Categories" )
Gets the list of available StopPoint additional information categories
def getDisruptionsByID(self, ids, getFamily: bool, includeRouteBlockedStops: bool, flattenResponse: bool)
-
Expand source code
def getDisruptionsByID( self, ids, getFamily: bool, includeRouteBlockedStops: bool, flattenResponse: bool, ): """ Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have Args: ids: A list of StopPoint ids (station naptan code e.g. 940GZZLUAS) getFamily: Specify true to return disruptions for entire family, or false to return disruptions for just this stop point. Defaults to false. includeRouteBlockedStops: Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false. flattenResponse: Specify true to return a flattened response, or false to return a nested response. Defaults to false. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{super(stopPoint, self).arrayToCSV(ids)}/Disruption", {'getFamily': getFamily, 'includeRouteBlockedStops': includeRouteBlockedStops, 'flattenResponse': flattenResponse}, )
Gets all disruptions for the specified StopPointId, plus disruptions for any child Naptan records it may have
Args
ids
- A list of StopPoint ids (station naptan code e.g. 940GZZLUAS)
getFamily
- Specify true to return disruptions for entire family, or false to return disruptions for just this stop point. Defaults to false.
includeRouteBlockedStops
- Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false.
flattenResponse
- Specify true to return a flattened response, or false to return a nested response. Defaults to false.
def getDisruptionsByMode(self, modes, includeRouteBlockedStops: bool)
-
Expand source code
def getDisruptionsByMode(self, modes, includeRouteBlockedStops: bool): """ Gets a distinct list of disrupted stop points for the given modes Args: modes: An array of modes e.g. ['tube', 'dlr'] includeRouteBlockedStops: Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Mode/{super(stopPoint, self).arrayToCSV(modes)}/Disruption", {'includeRouteBlockedStops': includeRouteBlockedStops}, )
Gets a distinct list of disrupted stop points for the given modes
Args
modes
- An array of modes e.g. ['tube', 'dlr']
includeRouteBlockedStops
- Specify true to return disruptions for route blocked stops, or false to return disruptions for all stops. Defaults to false.
def getInRadius(self,
stopTypes,
radius: int,
useStopPointHierarchy: bool,
modes,
categories,
returnLines: bool,
latitude: int,
longitude: int)-
Expand source code
def getInRadius( self, stopTypes, radius: int, useStopPointHierarchy: bool, modes, categories, returnLines: bool, latitude: int, longitude: int, ): """ Gets a list of StopPoints within {radius} by the specified criteria Args: stopTypes: An array of stop point types e.g. ['NaptanPublicBusCoachTram'] radius: The radius in metres. Defaults to 200. useStopPointHierarchy: Specify true to return stop points in the hierarchy, or false to return stop points at the specified radius. Defaults to false. modes: An array of modes e.g. ['tube', 'dlr'] categories: An array of categories e.g. ['tram', 'bus'] returnLines: Specify true to return the lines that service the stop point, or false to return the stop point itself. Defaults to false. latitude: The latitude of the location to search from. longitude: The longitude of the location to search from. """ return super(stopPoint, self).sendRequestUnified( "/StopPoint", { "stopTypes": super(stopPoint, self).arrayToCSV(stopTypes), "radius": radius, "useStopPointHierarchy": useStopPointHierarchy, "modes": super(stopPoint, self).arrayToCSV(modes), "categories": super(stopPoint, self).arrayToCSV(categories), "returnLines": returnLines, "latitude": latitude, "longitude": longitude, }, )
Gets a list of StopPoints within {radius} by the specified criteria
Args
stopTypes
- An array of stop point types e.g. ['NaptanPublicBusCoachTram']
radius
- The radius in metres. Defaults to 200.
useStopPointHierarchy
- Specify true to return stop points in the hierarchy, or false to return stop points at the specified radius. Defaults to false.
modes
- An array of modes e.g. ['tube', 'dlr']
categories
- An array of categories e.g. ['tram', 'bus']
returnLines
- Specify true to return the lines that service the stop point, or false to return the stop point itself. Defaults to false.
latitude
- The latitude of the location to search from.
longitude
- The longitude of the location to search from.
def getModes(self)
-
Expand source code
def getModes(self): """Gets the list of available StopPoint modes""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/Modes" )
Gets the list of available StopPoint modes
def getReachableStationsByID(self, naptanID: str, lineID: str, serviceTypes=None)
-
Expand source code
def getReachableStationsByID(self, naptanID: str, lineID: str, serviceTypes=None): """ Gets Stop points that are reachable from a station/line combination Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) lineID: A Line id (e.g. victoria) serviceTypes: An array of service types. Supported values: Regular, Night. Defaults to Regular. """ if serviceTypes is None: serviceTypes = ["Regular"] return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/CanReachOnLine/{lineID}", {"serviceTypes": super(stopPoint, self).arrayToCSV(serviceTypes)}, )
Gets Stop points that are reachable from a station/line combination
Args
naptanID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
lineID
- A Line id (e.g. victoria)
serviceTypes
- An array of service types. Supported values: Regular, Night. Defaults to Regular.
def getRouteSectionByID(self, naptanID: str, serviceTypes)
-
Expand source code
def getRouteSectionByID(self, naptanID: str, serviceTypes): """ Get the route sections for all the lines that service the given stop point id# Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) serviceTypes: An array of service types. Supported values: Regular, Night. """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/Route", {"serviceTypes": super(stopPoint, self).arrayToCSV(serviceTypes)}, )
Get the route sections for all the lines that service the given stop point id#
Args
naptanID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
serviceTypes
- An array of service types. Supported values: Regular, Night.
def getServiceTypesByID(self, stopPointID: str, lineIds, modes)
-
Expand source code
def getServiceTypesByID(self, stopPointID: str, lineIds, modes): """ Gets the service types for a given Stop Point Args: stopPointID: A StopPoint id (station naptan code e.g. 940GZZLUAS) lineIds: A list of Line ids (e.g. victoria) modes: An array of modes e.g. ['tube', 'dlr'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/ServiceTypes", {"id": stopPointID, "lineIds": lineIds, "modes": modes}, )
Gets the service types for a given Stop Point
Args
stopPointID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
lineIds
- A list of Line ids (e.g. victoria)
modes
- An array of modes e.g. ['tube', 'dlr']
def getStationArrivals(self, naptanID: str)
-
Expand source code
def getStationArrivals(self, naptanID: str): """ Get all service arrivals Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/Arrivals" )
Get all service arrivals
Args
naptanID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
def getTaxiRanksByID(self, naptanID: str)
-
Expand source code
def getTaxiRanksByID(self, naptanID: str): """ Gets a list of taxi ranks corresponding to the given stop point id Args: naptanID: A StopPoint id (station naptan code e.g. 940GZZLUAS) """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/{naptanID}/TaxiRanks" )
Gets a list of taxi ranks corresponding to the given stop point id
Args
naptanID
- A StopPoint id (station naptan code e.g. 940GZZLUAS)
def getTypes(self)
-
Expand source code
def getTypes(self): """Gets the list of available StopPoint types""" return super(stopPoint, self).sendRequestUnified( "/StopPoint/Meta/StopTypes" )
Gets the list of available StopPoint types
def search(self, name: str, modes)
-
Expand source code
def search(self, name: str, modes): """ Search StopPoints by their common name. Will not return a valid NaPTAN for HUB Args: name: The name of station to search for modes: An array of modes e.g. ['tube', 'dlr'] """ return super(stopPoint, self).sendRequestUnified( f"/StopPoint/Search/${name}", {"modes": super(stopPoint, self).arrayToCSV(modes)}, )
Search StopPoints by their common name. Will not return a valid NaPTAN for HUB
Args
name
- The name of station to search for
modes
- An array of modes e.g. ['tube', 'dlr']
Inherited members
class tflAPI (app_key)
-
Expand source code
class tflAPI(object): """TFL API""" def __init__(self, app_key): self.app_key = app_key def sendRequestUnified(self, uri: str, params = {}): """ Send a HTTP GET request to the TFL Unified API using your API Key Args: uri: The URI to send the request to params: The parameters to send with the request Returns: The response from the TFL Unified API """ fullURL = f"https://api.tfl.gov.uk:443{uri}?{urllib.parse.urlencode({'app_key': self.app_key})}" # If params is specified then convert it to a url encoded string if params: fullURL += f"&{urllib.parse.urlencode(params)}" # Send the request resource = urllib.request.urlopen(fullURL) return json.loads( resource.read().decode(resource.headers.get_content_charset()) ) def sendRequestTrackerNet(self, uri: str): """ Send a HTTP GET request to the TrackerNet API Args: uri: The URI to send the request to Returns: The response from the TrackerNet API """ data = urllib.request.urlopen( f"https://api.tfl.gov.uk:443/trackernet{uri}?{urllib.parse.urlencode({'app_key': self.app_key})}").read() return xmltodict.parse(data) @staticmethod def arrayToCSV(array): """ Convert array to a comma-separated string Args: array: The array to convert to a comma-separated string returns: The comma-separated string """ return ",".join(array) @staticmethod def getRFC3339(date_object): """ Convert date object to RFC3339 standard Args: date_object: The date object to convert Returns: The RFC3339 formatted string """ return date_object.isoformat("T") + "Z"
TFL API
Subclasses
- tflwrapper.accidentStats.accidentStats
- tflwrapper.airQuality.airQuality
- tflwrapper.bikePoint.bikePoint
- tflwrapper.crowding.crowding
- tflwrapper.disruptions.disruptions
- tflwrapper.line.line
- tflwrapper.mode.mode
- tflwrapper.occupancy.occupancy
- tflwrapper.road.road
- tflwrapper.stopPoint.stopPoint
- tflwrapper.trackerNet.trackerNet
- tflwrapper.travelTimes.travelTimes
Static methods
def arrayToCSV(array)
-
Expand source code
@staticmethod def arrayToCSV(array): """ Convert array to a comma-separated string Args: array: The array to convert to a comma-separated string returns: The comma-separated string """ return ",".join(array)
Convert array to a comma-separated string
Args
array
- The array to convert to a comma-separated string
returns: The comma-separated string
def getRFC3339(date_object)
-
Expand source code
@staticmethod def getRFC3339(date_object): """ Convert date object to RFC3339 standard Args: date_object: The date object to convert Returns: The RFC3339 formatted string """ return date_object.isoformat("T") + "Z"
Convert date object to RFC3339 standard
Args
date_object
- The date object to convert
Returns
The RFC3339 formatted string
Methods
def sendRequestTrackerNet(self, uri: str)
-
Expand source code
def sendRequestTrackerNet(self, uri: str): """ Send a HTTP GET request to the TrackerNet API Args: uri: The URI to send the request to Returns: The response from the TrackerNet API """ data = urllib.request.urlopen( f"https://api.tfl.gov.uk:443/trackernet{uri}?{urllib.parse.urlencode({'app_key': self.app_key})}").read() return xmltodict.parse(data)
Send a HTTP GET request to the TrackerNet API
Args
uri
- The URI to send the request to
Returns
The response from the TrackerNet API
def sendRequestUnified(self, uri: str, params={})
-
Expand source code
def sendRequestUnified(self, uri: str, params = {}): """ Send a HTTP GET request to the TFL Unified API using your API Key Args: uri: The URI to send the request to params: The parameters to send with the request Returns: The response from the TFL Unified API """ fullURL = f"https://api.tfl.gov.uk:443{uri}?{urllib.parse.urlencode({'app_key': self.app_key})}" # If params is specified then convert it to a url encoded string if params: fullURL += f"&{urllib.parse.urlencode(params)}" # Send the request resource = urllib.request.urlopen(fullURL) return json.loads( resource.read().decode(resource.headers.get_content_charset()) )
Send a HTTP GET request to the TFL Unified API using your API Key
Args
uri
- The URI to send the request to
params
- The parameters to send with the request
Returns
The response from the TFL Unified API
class trackerNet (app_key)
-
Expand source code
class trackerNet(tflAPI): """TrackerNet API""" def getPredictionSummary(self, line: str): """ Get detailed train prediction information for a nominated station on a nominated line within 100 minute range Args: line: The line code for the line (eg. C) """ return super(trackerNet, self).sendRequestTrackerNet( f"/PredictionSummary/{line}" ) def getPredictionDetailed(self, line: str, stationCode: str): """ Get detailed train prediction information for a nominated station on a nominated line within 100 minute range Args: line: The line code for the line (eg. C) stationCode: The station code for the station (eg. BNK) """ return super(trackerNet, self).sendRequestTrackerNet( f"/PredictionDetailed/{line}/{stationCode}" ) def getAllLinesStatus(self, incidentsOnly: bool): """ Get the status of all lines on the network indicating any delays, disruptions or suspensions on the lines. Args: incidentsOnly: Get line status information for lines with incidents only """ incidentsOnlyCheck = '/IncidentsOnly' if incidentsOnly else '' return super(trackerNet, self).sendRequestTrackerNet( f"/LineStatus{incidentsOnlyCheck}" ) def getAllStationStatus(self, incidentsOnly: bool): """ Get station status information for all stations Args: incidentsOnly: Get station status information for stations with incidents only """ incidentsOnlyCheck = '/IncidentsOnly' if incidentsOnly else '' return super(trackerNet, self).sendRequestTrackerNet( f"/StationStatus{incidentsOnlyCheck}" )
TrackerNet API
Ancestors
Methods
def getAllLinesStatus(self, incidentsOnly: bool)
-
Expand source code
def getAllLinesStatus(self, incidentsOnly: bool): """ Get the status of all lines on the network indicating any delays, disruptions or suspensions on the lines. Args: incidentsOnly: Get line status information for lines with incidents only """ incidentsOnlyCheck = '/IncidentsOnly' if incidentsOnly else '' return super(trackerNet, self).sendRequestTrackerNet( f"/LineStatus{incidentsOnlyCheck}" )
Get the status of all lines on the network indicating any delays, disruptions or suspensions on the lines.
Args
incidentsOnly
- Get line status information for lines with incidents only
def getAllStationStatus(self, incidentsOnly: bool)
-
Expand source code
def getAllStationStatus(self, incidentsOnly: bool): """ Get station status information for all stations Args: incidentsOnly: Get station status information for stations with incidents only """ incidentsOnlyCheck = '/IncidentsOnly' if incidentsOnly else '' return super(trackerNet, self).sendRequestTrackerNet( f"/StationStatus{incidentsOnlyCheck}" )
Get station status information for all stations
Args
incidentsOnly
- Get station status information for stations with incidents only
def getPredictionDetailed(self, line: str, stationCode: str)
-
Expand source code
def getPredictionDetailed(self, line: str, stationCode: str): """ Get detailed train prediction information for a nominated station on a nominated line within 100 minute range Args: line: The line code for the line (eg. C) stationCode: The station code for the station (eg. BNK) """ return super(trackerNet, self).sendRequestTrackerNet( f"/PredictionDetailed/{line}/{stationCode}" )
Get detailed train prediction information for a nominated station on a nominated line within 100 minute range
Args
line
- The line code for the line (eg. C)
stationCode
- The station code for the station (eg. BNK)
def getPredictionSummary(self, line: str)
-
Expand source code
def getPredictionSummary(self, line: str): """ Get detailed train prediction information for a nominated station on a nominated line within 100 minute range Args: line: The line code for the line (eg. C) """ return super(trackerNet, self).sendRequestTrackerNet( f"/PredictionSummary/{line}" )
Get detailed train prediction information for a nominated station on a nominated line within 100 minute range
Args
line
- The line code for the line (eg. C)
Inherited members
class travelTimes (app_key)
-
Expand source code
class travelTimes(tflAPI): """Travel Times from Unified API""" def getOverlay( self, z, pinLat, pinLon, mapCenterLat, mapCenterLon, scenarioTitle, timeOfDayID, modeID, width, height, direction, travelTimeInterval ): """ Gets the TravelTime overlay Args: z: The zoom level of the map pinLat: The latitude of the pin pinLon: The longitude of the pin mapCenterLat: The latitude of the map center mapCenterLon: The longitude of the map center scenarioTitle: The title of the scenario timeOfDayID: The time of day ID. Supported values: AM, INTER, PM modeID: The mode ID. width: The width of the map height: The height of the map direction: The direction of the travel travelTimeInterval: The travel time interval """ return super(travelTimes, self).sendRequestUnified( f"/TravelTimes/overlay/{z}/mapcenter/{mapCenterLat}/{mapCenterLon}/pinlocation/{pinLat}/{pinLon}/dimensions/{width}/{height}/" )
Travel Times from Unified API
Ancestors
Methods
def getOverlay(self,
z,
pinLat,
pinLon,
mapCenterLat,
mapCenterLon,
scenarioTitle,
timeOfDayID,
modeID,
width,
height,
direction,
travelTimeInterval)-
Expand source code
def getOverlay( self, z, pinLat, pinLon, mapCenterLat, mapCenterLon, scenarioTitle, timeOfDayID, modeID, width, height, direction, travelTimeInterval ): """ Gets the TravelTime overlay Args: z: The zoom level of the map pinLat: The latitude of the pin pinLon: The longitude of the pin mapCenterLat: The latitude of the map center mapCenterLon: The longitude of the map center scenarioTitle: The title of the scenario timeOfDayID: The time of day ID. Supported values: AM, INTER, PM modeID: The mode ID. width: The width of the map height: The height of the map direction: The direction of the travel travelTimeInterval: The travel time interval """ return super(travelTimes, self).sendRequestUnified( f"/TravelTimes/overlay/{z}/mapcenter/{mapCenterLat}/{mapCenterLon}/pinlocation/{pinLat}/{pinLon}/dimensions/{width}/{height}/" )
Gets the TravelTime overlay
Args
z
- The zoom level of the map
pinLat
- The latitude of the pin
pinLon
- The longitude of the pin
mapCenterLat
- The latitude of the map center
mapCenterLon
- The longitude of the map center
scenarioTitle
- The title of the scenario
timeOfDayID
- The time of day ID. Supported values: AM, INTER, PM
modeID
- The mode ID.
width
- The width of the map
height
- The height of the map
direction
- The direction of the travel
travelTimeInterval
- The travel time interval
Inherited members