def buildBusinessDetailsFromJson(self, json): if 'id' in json: business = Business() business.business_id = self.formatYellowPagesId(json['id']) business.name = json['name'] if 'address' in json: if json['address']: address = json['address'] business.city = address['city'] business.province = address['prov'] business.country = 'Canada' business.street = address['street'] if 'geoCode' in json: if json['geoCode']: geolocation = json['geoCode'] lat = geolocation['latitude'] lon = geolocation['longitude'] business.geolocation = GeoLocation(lat, lon) if 'phones' in json: if json['phones']: phones = json['phones'] for phone in phones: if 'type' in phone: phoneType = phone['type'] if phoneType == 'primary': business.phonenumber = phone['dispNum'] if 'merchantUrl' in json: if json['merchantUrl']: url = json['merchantUrl'] business.url = url return business else: return None
def convertDbBusinessToBusiness(self, dbBusiness): business = None if dbBusiness: business = Business() business.name = dbBusiness.name business.url = dbBusiness.url business.country = dbBusiness.country business.province = dbBusiness.province business.city = dbBusiness.city business.street = dbBusiness.street business.postalcode = dbBusiness.postalcode business.phonenumber = dbBusiness.phonenumber if dbBusiness.hidden != None: business.hidden = dbBusiness.hidden business.geolocation = self.convertGeoPTToGeoLocation(dbBusiness.location) business.business_id = str(dbBusiness.key().id()) return business
def buildBusinessFromJson(self, json): businesses = [] if 'listings' in json: listings = json['listings'] for listing in listings: business = Business() business.business_id = self.formatYellowPagesId(listing['id']) business.name = listing['name'] if 'address' in listing: if listing['address']: address = listing['address'] business.city = address['city'] business.province = address['prov'] business.country = 'Canada' business.street = address['street'] if 'geoCode' in listing: if listing['geoCode']: geolocation = listing['geoCode'] lat = geolocation['latitude'] lon = geolocation['longitude'] business.geolocation = GeoLocation(lat, lon) businesses.append(business) return businesses