def CreateChickenPlace(self, id, place_info): ctx = ndb.get_context() menu_page = yield ctx.urlfetch(HOST + place_info["identifier"]) if not menu_page.status_code == 200: raise ndb.Return(None) parser = BeautifulSoup.BeautifulSoup(menu_page.content) address_1 = parser.find( id="ctl00_ContentPlaceHolder1_RestInfo_lblRestAddress").text address_2 = parser.find( id="ctl00_ContentPlaceHolder1_RestInfo_lblRestZip").text address = "%s, %s" % (address_1, " ".join(address_2.split())) place = ChickenPlace() place.key = ndb.Key(ChickenPlace, id, namespace=self.NAME) place.has_chicken = False # Check if they actually serve chicken: for tag in parser.findAll("h2", attrs={"class": "H2MC"}): if "chicken" in tag.text.lower(): place.has_chicken = True if place.has_chicken: # If they don't serve chicken then don't save any of their info. F**k them. place.identifier = place_info["identifier"] place.title = place_info["title"] place.address = address raise ndb.Return(place)
def CreateChickenPlace(self, id, place_info): ctx = ndb.get_context() menu_page = yield ctx.urlfetch(HOST + place_info["identifier"]) if not menu_page.status_code == 200: raise ndb.Return(None) parser = BeautifulSoup.BeautifulSoup(menu_page.content) address_1 = parser.find(id="ctl00_ContentPlaceHolder1_RestInfo_lblRestAddress").text address_2 = parser.find(id="ctl00_ContentPlaceHolder1_RestInfo_lblRestZip").text address = "%s, %s"%(address_1, " ".join(address_2.split())) place = ChickenPlace() place.key = ndb.Key(ChickenPlace, id, namespace=self.NAME) place.has_chicken = False # Check if they actually serve chicken: for tag in parser.findAll("h2", attrs={"class":"H2MC"}): if "chicken" in tag.text.lower(): place.has_chicken = True if place.has_chicken: # If they don't serve chicken then don't save any of their info. F**k them. place.identifier = place_info["identifier"] place.title = place_info["title"] place.address = address raise ndb.Return(place)
def GetAvailablePlaces(self, postcode=None, location=None): encoded = geohash.encode(location.lat, location.lon, precision=10) result = memcache.get(encoded, namespace=self.NAME) if result is None: result = json.loads(urlfetch.fetch(BASE_URL.format(location.lat, location.lon)).content) memcache.set(encoded, result, namespace=self.NAME) places = [] for place in result: chicken_place = ChickenPlace() chicken_place.title = place["storeName"] chicken_place.address = "%s %s %s %s"%(place["address1"], place["address2"], place["address3"], place["postcode"]) chicken_place.location = ndb.GeoPt(place["latitude"], place["longitude"]) places.append(chicken_place) return places
def get(self): # Flush old JustEat chickenplaces ten_days_ago = datetime.date.today() - datetime.timedelta(days=10) cursor = None more = True keys = [] while more: results, cursor, more = ChickenPlace.query(namespace="JustEat").filter(ChickenPlace.created < ten_days_ago) \ .fetch_page(150, keys_only=True, start_cursor=cursor) keys.extend(results) logging.info("Deleting %s old ChickenPlaces"%len(keys)) ndb.delete_multi(keys) logging.info("Deleted!")
def GetAvailablePlaces(self, postcode=None, location=None): encoded = geohash.encode(location.lat, location.lon, precision=10) result = memcache.get(encoded, namespace=self.NAME) if result is None: result = json.loads( urlfetch.fetch(BASE_URL.format(location.lat, location.lon)).content) memcache.set(encoded, result, namespace=self.NAME) places = [] for place in result: chicken_place = ChickenPlace() chicken_place.title = place["storeName"] chicken_place.address = "%s %s %s %s" % ( place["address1"], place["address2"], place["address3"], place["postcode"]) chicken_place.location = ndb.GeoPt(place["latitude"], place["longitude"]) places.append(chicken_place) return places