def get_tfl_prediction_summaries(): """ Go through TfL's PredictionSummary API and return list of XML Trees for every single line """ #pylint: disable=W0703 browser = WMTBrowser() all_train_data = {} line_codes = ('B', 'C', 'D', 'H', 'J', 'M', 'N', 'P', 'V', 'W') for line_code in line_codes: tfl_url = "http://cloud.tfl.gov.uk/TrackerNet/PredictionSummary/%s" % line_code try: all_train_data[line_code] = browser.fetch_xml_tree(tfl_url) except Exception: print "Couldn't get data for %s" % line_code continue return all_train_data
def parse_stations_from_kml(filter_function=lambda a, b: True): """ Parses KML file of stations & associated data, and returns them as a dictionary """ stations = {} kml = WMTBrowser().fetch_xml_tree('file:///%s/sourcedata/tube-locations.kml' % os.getcwd()) for station in kml.findall('.//Placemark'): name = station.find('name').text.strip().replace(' Station', '') style = station.find('styleUrl').text if filter_function(name, style): coordinates = station.find('Point/coordinates').text (lon, lat) = tuple([float(c) for c in coordinates.split(',')[0:2]]) (lat, lon) = convertWGS84toOSGB36(lat, lon)[:2] (easting, northing) = LatLongToOSGrid(lat, lon) stations[name.lower()] = {'name': name, 'location_easting': str(easting), 'location_northing': str(northing), 'code': '', 'lines': '', 'inner': '', 'outer': ''} return stations