def get_busway_routes(callback=None): """ scrape the routes :type callback:common.callbacks.Callback :rtype list[BusRoute] """ routes_list = [] try: scrapper = scrap( "https://en.wikipedia.org/w/index.php?title=TransJakarta_Corridors&oldid=679760031" ) main_content = scrapper.find('div', attrs={'id': 'mw-content-text'}) tables = main_content.find_all('table', {'class': 'wikitable'}) for table in tables: route = BusRoute() rows = table.find_all('tr') corridor_name = rows[0].find('th').find('a')['title'] new_rows = rows[2:] station_list = [] for row in new_rows: station_name = row_parser(row.find_all('td')[1].getText()) station_list.append("Halte " + station_name) route.stations = station_list route.corridor_name = corridor_name routes_list.append(route) except Exception, e: callback.on_failure(e) __logger.error(e)
def get_busway_routes(callback=None): """ scrape the routes :type callback:common.callbacks.Callback :rtype list[BusRoute] """ routes_list = [] try: scrapper = scrap("https://en.wikipedia.org/w/index.php?title=TransJakarta_Corridors&oldid=679760031") main_content = scrapper.find('div', attrs={'id': 'mw-content-text'}) tables = main_content.find_all('table', {'class': 'wikitable'}) for table in tables: route = BusRoute() rows = table.find_all('tr') corridor_name = rows[0].find('th').find('a')['title'] new_rows = rows[2:] station_list = [] for row in new_rows: station_name = row_parser(row.find_all('td')[1].getText()) station_list.append("Halte " + station_name) route.stations = station_list route.corridor_name = corridor_name routes_list.append(route) except Exception, e: callback.on_failure(e) __logger.error(e)
def test_bus_routes_accessor(self): bus_route = BusRoute() bus_route.stations = ['Station1', 'Station 2'] bus_route.corridor_name = 'Test' bus_route_accessor.reset() bus_route_accessor.upset_bus_route(bus_route) post_bus_route = bus_route_accessor.get_bus_route_by_corridor('Test') assert (post_bus_route.stations[1] == bus_route.stations[1]) assert (post_bus_route.stations[0] == bus_route.stations[0])
def to_bus_route(self): bus_route = BusRoute() bus_route.corridor_name = self.corridor_name bus_route.stations = self.stations.split(',') return bus_route