Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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)
Esempio n. 5
0
    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
Esempio n. 6
0
    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
Esempio n. 7
0
    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
Esempio n. 8
0
 def get_stations(self, data):
     for station in data['stations']:
         name = station['description']
         longitude = float(station['lng'])
         latitude = float(station['lat'])
         bikes = int(station['free_bikes'])
         free = int(station['free_spaces'])
         extra = {
             'slots': int(station['total_spaces'])
         }
         station = BikeShareStation(name, latitude, longitude, bikes, free,
                                    extra)
         yield station
Esempio n. 9
0
    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
Esempio n. 10
0
    def get_stations(self, dom):
        ns = {'kml': 'http://www.opengis.net/kml/2.2'}
        for placemark in dom.xpath('//kml:Placemark', namespaces=ns):
            name = placemark.findtext('kml:name', namespaces=ns)
            info = placemark.findtext('kml:description', namespaces=ns)
            station_uid, bikes, free = map(int,
                                           re.findall(r'\w+\:\s*(\d+)', info))
            longitude, latitude = placemark.findtext(
                'kml:Point/kml:coordinates', namespaces=ns).split(',')
            latitude = float(latitude)
            longitude = float(longitude)
            extra = {
                'uid': station_uid,
            }

            station = BikeShareStation(name, latitude, longitude, bikes, free,
                                       extra)
            yield station
Esempio n. 11
0
    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
Esempio n. 12
0
    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