Esempio n. 1
0
    def parse_pods(cls, locations, zip_filter=None):
        '''
          "locations": [
          {
              "location_id": 95724,
              "display_name": "355 Binney St - Kendall Cinema",
              "address": {
                "street": "355 Binney St",
                "city": "Cambridge",
                "region_name": "Massachusetts",
                "postal_code": "02139",
                "country_code": "US"
              },
              "coordinates": {
                "lat": 42.3673905200087,
                "lng": -71.0897461574591
              },
              "num_vehicles": 8,
              "products": [
                {
                  "type": "standard",
                  "label": "Zipcars"
                }
              ],
              "vehicles": [ { ... }, {...}]
          }]
        '''
        pods = []
        vehicles = []
        for l in locations:
            id = object_utils.dval(l, 'location_id')

            # optionally filter by zipcode
            if zip_filter:
                address = object_utils.dval(l, 'address')
                zip = object_utils.dval(address, 'postal_code')
                if not re_utils.contains(zip_filter, zip):
                    log.debug(
                        "skipping record: {} not in Zipcar postal_code {}".
                        format(zip_filter, zip))
                    continue

            # make pod
            pod = ZipcarPod(id, l)
            pods.append(pod)

            # make vehicles
            #import pdb; pdb.set_trace()
            v = ZipcarVehicle.make_vehicles(id, l)
            if v:
                vehicles.extend(v)

        return pods, vehicles
Esempio n. 2
0
    def parse_pods(cls, locations, zip_filter=None):
        '''
          "locations": [
          {
              "location_id": 95724,
              "display_name": "355 Binney St - Kendall Cinema",
              "address": {
                "street": "355 Binney St",
                "city": "Cambridge",
                "region_name": "Massachusetts",
                "postal_code": "02139",
                "country_code": "US"
              },
              "coordinates": {
                "lat": 42.3673905200087,
                "lng": -71.0897461574591
              },
              "num_vehicles": 8,
              "products": [
                {
                  "type": "standard",
                  "label": "Zipcars"
                }
              ],
              "vehicles": [ { ... }, {...}]
          }]
        '''
        pods = []
        vehicles = []
        for l in locations:
            id = object_utils.dval(l, 'location_id')

            # optionally filter by zipcode
            if zip_filter:
                address = object_utils.dval(l, 'address')
                zip = object_utils.dval(address, 'postal_code')
                if not re_utils.contains(zip_filter, zip):
                    log.debug("skipping record: {} not in Zipcar postal_code {}".format(zip_filter, zip))
                    continue

            # make pod
            pod = ZipcarPod(id, l)
            pods.append(pod)


            # make vehicles
            #import pdb; pdb.set_trace()
            v = ZipcarVehicle.make_vehicles(id, l)
            if v:
                vehicles.extend(v)

        return pods, vehicles
Esempio n. 3
0
 def load_zipcar_data(self):
     try:
         data = self.get_data()
         data = object_utils.dval(data, 'locations')
         if data:
             self.pods, self.vehicles = UpdatePositions.parse_pods(data, self.zipcode_filter)
         else:
             raise Exception('could not load any Zipcode data {0}'.format(data))
     except Exception, err:
         log.exception('Exception: {0}'.format(err))
Esempio n. 4
0
 def load_zipcar_data(self):
     try:
         data = self.get_data()
         data = object_utils.dval(data, 'locations')
         if data:
             self.pods, self.vehicles = UpdatePositions.parse_pods(
                 data, self.zipcode_filter)
         else:
             raise Exception(
                 'could not load any Zipcode data {0}'.format(data))
     except Exception, err:
         log.exception('Exception: {0}'.format(err))
Esempio n. 5
0
    def make_vehicles(cls, pod_id, pod_data):
        '''
            "coordinates": {
                "lat": 42.3673905200087,
                "lng": -71.0897461574591
            },

        '''
        ret_val = []

        vehicles = object_utils.dval_list(pod_data, 'vehicles')
        for vehicle_data in vehicles:
            vid = object_utils.dval(vehicle_data, 'vehicle_id')
            zc = ZipcarVehicle(vid, pod_id)
            zc.set_attributes(pod_data, vehicle_data)
            ret_val.append(zc)
        return ret_val
Esempio n. 6
0
    def make_vehicles(cls, pod_id, pod_data):
        '''
            "coordinates": {
                "lat": 42.3673905200087,
                "lng": -71.0897461574591
            },

        '''
        ret_val = []

        vehicles = object_utils.dval_list(pod_data, 'vehicles')
        for vehicle_data in vehicles:
            vid = object_utils.dval(vehicle_data, 'vehicle_id')
            zc = ZipcarVehicle(vid, pod_id)
            zc.set_attributes(pod_data, vehicle_data)
            ret_val.append(zc)
        return ret_val
Esempio n. 7
0
    def set_attributes(self, pod_data, vehicle_data):
        ''' copy known values from the dict into this object, then update the timestamp
        {
          "vehicle_id": 1179454588,
          "vehicle_name": "Gadsen",
          "make_model": "Volkswagen Golf",
          "style": "5-door",
          "year": 2014,
          "hourly_rate": 10.5,
          "daily_rate": 78,
          "currency_code": "USD",
          "product_types": [
            {
              "type": "standard",
              "label": "Zipcars"
            }
          ],
          "images": {
            "thumb": "http://media.zipcar.com/images/model-image?model_id=980237689&mode=thumb",
            "mobile": "http://media.zipcar.com/images/model-image?model_id=980237689&mode=med",
            "desktop": "http://media.zipcar.com/images/model-image?model_id=980237689"
          },
          "actions": [
            {
              "type": "learn_more",
              "label": "Learn More",
              "url": "http://www.zipcar.com/?mobile_p=0&utm_source=partner&utm_medium=api&utm_campaign=partner_app&utm_content=version0"
            },
            {
              "type": "reserve",
              "label": "Reserve",
              "url": "https://members.zipcar.com/reservations?utm_source=partner&utm_medium=api&utm_campaign=partner_app&utm_content=version0"
            }
          ]
        }
        '''
        self.name   = object_utils.dval(vehicle_data, 'vehicle_name')
        self.model  = object_utils.dval(vehicle_data, 'make_model')
        self.style  = object_utils.dval(vehicle_data, 'style')
        self.year   = object_utils.dval(vehicle_data, 'year')
        self.hourly = object_utils.dval(vehicle_data, 'hourly_rate')
        self.daily  = object_utils.dval(vehicle_data, 'daily_rate')

        images = object_utils.dval(vehicle_data, 'images')
        self.img_thumb = object_utils.dval(images, 'thumb')
        self.img_small = object_utils.dval(images, 'mobile')
        self.img_large = object_utils.dval(images, 'desktop')

        urls = object_utils.dval_list(vehicle_data, 'actions')
        for u in urls:
            type = object_utils.dval(u, 'type')
            if type == 'reserve':
                self.url_reserve = object_utils.dval(u, 'url')
            if type == 'learn_more':
                self.url_info = object_utils.dval(u, 'url')

        coord = object_utils.dval(pod_data, 'coordinates')
        address = object_utils.dval(pod_data, 'address')
        self.lat, self.lon  = geo_utils.get_coord_from_dict(coord)
        self.street, self.city, self.state, self.zip = geo_utils.get_address_from_dict(address)
        self.updated = datetime.datetime.now()
Esempio n. 8
0
    def set_attributes(self, pod_data, vehicle_data):
        ''' copy known values from the dict into this object, then update the timestamp
        {
          "vehicle_id": 1179454588,
          "vehicle_name": "Gadsen",
          "make_model": "Volkswagen Golf",
          "style": "5-door",
          "year": 2014,
          "hourly_rate": 10.5,
          "daily_rate": 78,
          "currency_code": "USD",
          "product_types": [
            {
              "type": "standard",
              "label": "Zipcars"
            }
          ],
          "images": {
            "thumb": "http://media.zipcar.com/images/model-image?model_id=980237689&mode=thumb",
            "mobile": "http://media.zipcar.com/images/model-image?model_id=980237689&mode=med",
            "desktop": "http://media.zipcar.com/images/model-image?model_id=980237689"
          },
          "actions": [
            {
              "type": "learn_more",
              "label": "Learn More",
              "url": "http://www.zipcar.com/?mobile_p=0&utm_source=partner&utm_medium=api&utm_campaign=partner_app&utm_content=version0"
            },
            {
              "type": "reserve",
              "label": "Reserve",
              "url": "https://members.zipcar.com/reservations?utm_source=partner&utm_medium=api&utm_campaign=partner_app&utm_content=version0"
            }
          ]
        }
        '''
        self.name = object_utils.dval(vehicle_data, 'vehicle_name')
        self.model = object_utils.dval(vehicle_data, 'make_model')
        self.style = object_utils.dval(vehicle_data, 'style')
        self.year = object_utils.dval(vehicle_data, 'year')
        self.hourly = object_utils.dval(vehicle_data, 'hourly_rate')
        self.daily = object_utils.dval(vehicle_data, 'daily_rate')

        images = object_utils.dval(vehicle_data, 'images')
        self.img_thumb = object_utils.dval(images, 'thumb')
        self.img_small = object_utils.dval(images, 'mobile')
        self.img_large = object_utils.dval(images, 'desktop')

        urls = object_utils.dval_list(vehicle_data, 'actions')
        for u in urls:
            type = object_utils.dval(u, 'type')
            if type == 'reserve':
                self.url_reserve = object_utils.dval(u, 'url')
            if type == 'learn_more':
                self.url_info = object_utils.dval(u, 'url')

        coord = object_utils.dval(pod_data, 'coordinates')
        address = object_utils.dval(pod_data, 'address')
        self.lat, self.lon = geo_utils.get_coord_from_dict(coord)
        self.street, self.city, self.state, self.zip = geo_utils.get_address_from_dict(
            address)
        self.updated = datetime.datetime.now()