Пример #1
0
def addOffers(self, offers, site):
    if not offers:
        return

    newOffers = []
    for offer in offers:
        try:
            image_offer = urlfetch.Fetch(url=offer[1], deadline=10).content
        except urlfetch.Error:
            image_offer = urlfetch.fetch(url="http://www.escolhaofertas.com.br/static/images/img_404.png").content
            logging.error("Image Timeout")
        newOffers.append(
            Offer(
                link=offer[0],
                img=offer[1],
                image=db.Blob(image_offer),
                desc=offer[2] + offer[3],
                price="",
                site_name=site,
                views=0,
            )
        )
    db.put(newOffers)
    memcache.flush_all()
    memcache.set("num_offers", Offer.all().count())
    logging.info("Offers length :" + str(len(newOffers)))
    self.response.out.write(site + ": Offers added")
Пример #2
0
	def get(self):
		numOffers = memcache.get('num_offers')
		t = datetime.today() 
		uploaded_date_offers = t.strftime("%d/%m/%y")

		offers = Offer.all().order("__key__").fetch(PAGESIZE)
		offers = list(offers)
		#uploaded_date_offers = memcache.get('last_update')
		self.render('index.html', offers=offers, num_offers=numOffers, uploaded_date_offers=uploaded_date_offers)
Пример #3
0
	def get(self, page):
		offers_page = memcache.get("offers_page"+page)
		if offers_page is not None:
			logging.info("offers_page"+str(page)+" HIT")
			self.response.out.write(json.dumps(offers_page))
			return

		offers = Offer.all().order("__key__").fetch(PAGESIZE + 1, (int(page)-1) * PAGESIZE)
		num_offers = len(offers)

		offers = offers[:PAGESIZE]
		if num_offers == PAGESIZE+1:
			response = self.createJsonOffers(page,offers)
		elif num_offers > 0:
			response = self.createJsonOffers(page,offers,0)
		else:
			response = '{more:-1}'

		memcache.set("offers_page"+page,response)
		logging.info("offers_page"+str(page)+" Miss")
		self.response.out.write(json.dumps(response))