def update(self, scraper=None): if scraper is None: scraper = PyBikesScraper() raw = scraper.request(self.feed_url) tree = etree.fromstring(raw) stations = [] for location in tree.xpath('//location'): station = BikeShareStation() uid = location.find('Id').text address = location.find('Address').text station.name = "%s - %s" % (uid, address) station.latitude = float(location.find('Latitude').text) station.longitude = float(location.find('Longitude').text) station.bikes = int(location.find('Bikes').text) station.free = int(location.find('Dockings').text) station.extra = { 'uid': uid, 'address': address } stations.append(station) self.stations = stations
def update(self, scraper=None): if scraper is None: scraper = PyBikesScraper() data = scraper.request(self.feed_url) tree = etree.XML(data.encode('utf-8')) namespaces = { 'Bicicletas': 'http://bicis.buenosaires.gob.ar/ServiceBicycle.asmx' } stations_XML = tree.xpath('//Bicicletas:Estacion', namespaces=namespaces) stations = [] for station_XML in stations_XML: station = BikeShareStation() uid = station_XML.find('Bicicletas:EstacionId', namespaces=namespaces).text address = station_XML.find('Bicicletas:Lugar', namespaces=namespaces).text + ' ' + station_XML.find('{http://bicis.buenosaires.gob.ar/ServiceBicycle.asmx}Numero').text station.name = station_XML.find('Bicicletas:EstacionNombre', namespaces=namespaces).text station.latitude = station_XML.find('Bicicletas:Latitud', namespaces=namespaces).text station.longitude = station_XML.find('Bicicletas:Longitud', namespaces=namespaces).text station.bikes = int(station_XML.find('Bicicletas:AnclajesTotales', namespaces=namespaces).text) station.free = int(station_XML.find('Bicicletas:BicicletaDisponibles', namespaces=namespaces).text) station.extra = { 'uid': uid, 'address': address } if station.latitude and station.longitude: station.latitude = float(station.latitude) station.longitude = float(station.longitude) stations.append(station) self.stations = stations
def update(self, scraper=None): if scraper is None: scraper = PyBikesScraper() data = scraper.request(self.feed_url) tree = etree.XML(data.encode('utf-8')) namespaces = { 'Bicicletas': 'http://bicis.buenosaires.gob.ar/ServiceBicycle.asmx' } stations_XML = tree.xpath('//Bicicletas:Estacion', namespaces=namespaces) stations = [] for station_XML in stations_XML: station = BikeShareStation() uid = station_XML.find('Bicicletas:EstacionId', namespaces=namespaces).text address = station_XML.find( 'Bicicletas:Lugar', namespaces=namespaces ).text + ' ' + station_XML.find( '{http://bicis.buenosaires.gob.ar/ServiceBicycle.asmx}Numero' ).text station.name = station_XML.find('Bicicletas:EstacionNombre', namespaces=namespaces).text station.latitude = station_XML.find('Bicicletas:Latitud', namespaces=namespaces).text station.longitude = station_XML.find('Bicicletas:Longitud', namespaces=namespaces).text station.bikes = int( station_XML.find('Bicicletas:AnclajesTotales', namespaces=namespaces).text) station.free = int( station_XML.find('Bicicletas:BicicletaDisponibles', namespaces=namespaces).text) station.extra = {'uid': uid, 'address': address} if station.latitude and station.longitude: station.latitude = float(station.latitude) station.longitude = float(station.longitude) stations.append(station) self.stations = stations
def update(self, scraper=None): if scraper is None: scraper = PyBikesScraper() status_fuzzle = scraper.request(self.status_url) location_dom = etree.fromstring(self.kml_file) status_dom = html.fromstring(status_fuzzle) placemarks = location_dom.xpath("//kml:Placemark", namespaces = _kml_ns) stations = [] for placemark in placemarks: name = placemark.findtext('kml:name', namespaces = _kml_ns) name_id = placemark.findtext('kml:description', namespaces = _kml_ns) coor = map( float, placemark.findtext('.//kml:coordinates', namespaces = _kml_ns). split(',')[0:2] ) # Find a status table with the name_id of this station, XPath # performance on this query is not really costly so far. try: (status,) = status_dom.xpath(_xpath_q % name_id) except ValueError: # Not found.. move along? continue m = re.search(_re_bikes_slots, status) bikes = int(m.group('bikes')) slots = int(m.group('slots')) station = BikeShareStation() station.name = name station.latitude = coor[1] station.longitude = coor[0] station.bikes = bikes station.free = slots - bikes station.extra = { 'slots': slots } stations.append(station) self.stations = stations
def update(self, scraper=None): if scraper is None: scraper = PyBikesScraper() status_fuzzle = scraper.request(self.status_url) location_dom = etree.fromstring(self.kml_file) status_dom = html.fromstring(status_fuzzle) placemarks = location_dom.xpath("//kml:Placemark", namespaces=_kml_ns) stations = [] for placemark in placemarks: name = placemark.findtext('kml:name', namespaces=_kml_ns) name_id = placemark.findtext('kml:description', namespaces=_kml_ns) coor = list( map( float, placemark.findtext('.//kml:coordinates', namespaces=_kml_ns).split(',')[0:2])) # Find a status table with the name_id of this station, XPath # performance on this query is not really costly so far. try: (status, ) = status_dom.xpath(_xpath_q % name_id) except ValueError: # Not found.. move along? continue m = re.search(_re_bikes_slots, status) bikes = int(m.group('bikes')) slots = int(m.group('slots')) station = BikeShareStation() station.name = name station.latitude = coor[1] station.longitude = coor[0] station.bikes = bikes station.free = slots - bikes station.extra = {'slots': slots} stations.append(station) self.stations = stations