def update(self): self.tube_status = getJsonFromURL( "https://api.tfl.gov.uk/line/mode/tube/status") self.dlr_status = getJsonFromURL( "https://api.tfl.gov.uk/line/mode/dlr/status") self.lines_data = getJsonFromURL( "https://api.tfl.gov.uk/line/mode/tube") self.updated = datetime.now().strftime("%d-%m-%Y %H:%M")
def getRoutesOnLine(self, line_ID): routes = [] allRoutes = getJsonFromURL("https://api.tfl.gov.uk/line/" + line_ID + "/route") for item in allRoutes["routeSections"]: routes.append(item["name"].replace('Underground Station', '')) return routes
def getStationsOnLine(self, line_ID): stations = [] stations_raw = getJsonFromURL("https://api.tfl.gov.uk/line/" + line_ID + "/stoppoints") for item in stations_raw: stations.append(item["commonName"].replace('Underground Station', '')) return stations
def getRail(self): rail_status = getJsonFromURL("https://api.tfl.gov.uk/line/mode/national-rail/status") headers = ["Line", "Status", "Issues"] data = [] for item in rail_status: if item["lineStatuses"][0]["statusSeverityDescription"] != "Good Service": data.append([item["name"], item["lineStatuses"][0]["statusSeverityDescription"]]) else: data.append([item["name"], item["lineStatuses"][0]["statusSeverityDescription"]]) table = "Last Updated: " + self.updated + "\n" + columnar(data, headers) return table
def getAllStations(self, id_select): stations_withDuplicates = [] for item in self.getLines(True): stations_raw = getJsonFromURL("https://api.tfl.gov.uk/line/" + item + "/stoppoints") for item in stations_raw: if id_select: stations_withDuplicates.append(item["id"]) else: temp = item["commonName"].replace('Underground Station', '') temp = temp.replace('DLR Station', '') stations_withDuplicates.append(temp) stations = list(dict.fromkeys(stations_withDuplicates)) return stations
def getDlrStations(self): stations_raw = getJsonFromURL("https://api.tfl.gov.uk/line/dlr/stoppoints") stations = [] for item in stations_raw: stations.append(item["commonName"].replace(' DLR Station', '')) return stations