def update(self, scraper=None): scraper = scraper or utils.PyBikesScraper() stations = [] data = json.loads(scraper.request(self.feed_url)) for station in data: longitude = float(station.get('lon') or station['longitude']) latitude = float(station.get('lat') or station['latitude']) name = station['standName'] free = None bikes = int(station['bikecount']) if 'slotcount' in station: free = int(station['slotcount']) extra = { 'uid': int(station['standId']), 'photo': station.get('standPhoto'), 'description': station.get('standDescription'), } station = BikeShareStation(name, latitude, longitude, bikes, free, extra) stations.append(station) self.stations = stations
def update(self, scraper=None): scraper = scraper or utils.PyBikesScraper() stations = [] data = json.loads(scraper.request(self.feed_url)) for station in data: # Skip "Loldesign" stations if station['googleMapY'] == "" or station['googleMapX'] == "": continue longitude = float(station['googleMapY']) latitude = float(station['googleMapX']) name = station['name'] free = int(station['available_slots_size']) bikes = int(station['unavailable_slots_size']) extra = { 'uid': int(station['id']), 'open': station['status'] == 'Ativa', 'number': int(station['station_number']), 'bike_uids': [bike['id'] for bike in station['bikes']] } station = BikeShareStation(name, latitude, longitude, bikes, free, extra) stations.append(station) if self.bounding_box: stations = utils.filter_bounds(stations, None, self.bounding_box) self.stations = list(stations)
def update(self, scraper=None): if scraper is None: scraper = utils.PyBikesScraper() stations = [] """ Looks like: var sites = [['<p><strong>001-Slough Train Station</strong></p>', 51.511350,-0.591562, , '<p><strong>001-Slough Train Station</strong></p> <p>Number of bikes available: 17</p> <p>Number of free docking points: 15</p>'], ...]; """ DATA_RGX = r'var sites = (\[.+?\]);' page = scraper.request(self.feed_url) data = re.search(DATA_RGX, page).group(1) _stations = demjson.decode(data) for _station in _stations: latitude = float(_station[1]) longitude = float(_station[2]) tree = html.fromstring(_station[4]) name, bikes, free = tree.xpath('//p//text()') bikes = int(re.search(r'\d+', bikes).group()) free = int(re.search(r'\d+', free).group()) # Matches (<number>)<symbol?><space?>name uuid = re.search(r'(\d+)[\W]?\s*\w+', name) uuid = uuid.group(1) extra = {'uuid': uuid} station = BikeShareStation(name, latitude, longitude, bikes, free, extra) stations.append(station) self.stations = stations
def update(self, scraper=None): scraper = scraper or utils.PyBikesScraper() stations = [] data = scraper.request(self.feed_url) dom = etree.fromstring(data.encode('utf-8')) stations = self.get_stations(dom) self.stations = list(stations)
def update(self, scraper=None): scraper = scraper or utils.PyBikesScraper() stations = [] data = json.loads(scraper.request(self.feed_url)) stations = self.get_stations(data) if self.bbox: stations = utils.filter_bounds(stations, None, self.bbox) self.stations = list(stations)
def update(self, scraper=None): if scraper is None: scraper = utils.PyBikesScraper() stations = [] """ Looks like: { u'number_right_slots':7, u'status':u'Ativa', u'station_number':1, u'password':None, u'description':None, u'total_bikes':None, u'created_at':u'2013-10-03T02:37:48-03:00', u'available_slots_size':10, u'updated_at':u'2014-06-27T15:11:21-03:00', u'id':7, u'status_to_human':u'Ativa', u'bikes':[...], u'number_left_slots':6, u'address':u'25.12.135.240', u'unavailable_slots_size':0, u'type_station':u'with_slots', u'mapX':None, u'mapY':None, u'googleMapY':u'-49.630102', u'googleMapX':u'-23.052386', u'name':u'Lago' } """ data = json.loads(scraper.request(self.feed_url)) for station in data: # Skip "Loldesign" stations if station['googleMapY'] == "" or station['googleMapX'] == "": continue longitude = float(station['googleMapY']) latitude = float(station['googleMapX']) # Skip "test" stations if self.bounding_box: point = geometry.Point(longitude, latitude) if not self.bounding_box.contains(point): continue name = station['name'] free = int(station['available_slots_size']) bikes = int(station['unavailable_slots_size']) extra = { 'uid': int(station['id']), 'open': station['status'] == 'Ativa', 'number': int(station['station_number']), 'bike_uids': [bike['id'] for bike in station['bikes']] } station = BikeShareStation(name, latitude, longitude, bikes, free, extra) stations.append(station) self.stations = stations