Beispiel #1
0
    def get(self, name):
        if not users.get_current_user():
            self.redirect(users.create_login_url(self.request.uri))
        logging.info('Iniciando busca')
        results = search_metacritic(name, 'game')
        logging.info('Fetch concluido')
        output = []

        for result in results:
            query = Img.all()
            query.filter('url =', result[1])
            img = query.fetch(1)[0]
            query = Game.all()
            query.filter('cover =', img)
            if not query.count():
                platform = str(result[1])[:str(result[1]).rfind('/')].replace('/game/','')
                game = Game(name=str(result[0]),cover=img,platform=platform,score=str(result[2]))
                game.put()
            else:
                game = query.fetch(1)[0]
            output.append([img.key().id(), result[0], game.key().id()])

        template_values = {'results': output}

        path = os.path.join(os.path.dirname(__file__), 'search.html')
        self.response.out.write(template.render(path, template_values))
Beispiel #2
0
    def get(self, name):
        if not users.get_current_user():
            self.redirect(users.create_login_url(self.request.uri))

        results = search_metacritic(name, 'movie')

        output = []

        for result in results:
            query = Img.all()
            query.filter('url =', result[1])
            img = query.fetch(1)[0]
            query = Movie.all()
            query.filter('cover =', img)
            if not query.count():
                movie = Movie(name=str(result[0]),cover=img,score=str(result[2]))
                movie.put()
            else:
                movie = query.fetch(1)[0]
            output.append([img.key().id(), result[0], movie.key().id()])

        template_values = {'results': output}

        path = os.path.join(os.path.dirname(__file__), 'search.html')
        self.response.out.write(template.render(path, template_values))
Beispiel #3
0
def search_metacritic(name, tag):
    try:
        name = name.replace("%20", "+")
        logging.info("iniciando fecth de " + str(name))
        soup = BeautifulSoup(
            urlfetch.fetch("http://www.metacritic.com/search/" + str(tag) + "/" + str(name) + "/results").content
        )

        divs = soup.findAll("div", attrs={"class": "main_stats"})

        results = [[divs[i].h3.a.string, divs[i].h3.a.get("href"), extract_score(divs[i])] for i in range(len(divs))]
        logging.info("coletando imagens")
        for result in results:
            query = Img.all()
            query.filter("url =", result[1])
            if not query.count():
                img = Img(data=db.Blob(extract_img(result[1])), url=result[1])
                img.put()
        return results
    except Exception, e:
        logging.info("ERRO :" + str(e))
        return search_metacritic(name, tag)