Exemple #1
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))
Exemple #2
0
def home():

    q = Movie.all()
    q.order("-votes")

    return render_template('home.html',
                           movies=q.run(limit=11),
                           form=SearchForm(),
                           image_path=settings.IMAGE_PATH,
                           total=q.count(),
                           offset=0)
Exemple #3
0
def movies():
    
    if request.is_xhr:
    
        q = Movie.all()
        q.order("-votes")
    
        limit = 11
        offset = 0
    
        if "limit" in request.form:
            try:
                limit = int(request.form['limit'])
            except Exception, e:
                pass
    
        if "offset" in request.form:
            try:
                offset = int(request.form['offset'])
            except Exception, e:
                pass
Exemple #4
0
def movies():

    if request.is_xhr:

        q = Movie.all()
        q.order("-votes")

        limit = 11
        offset = 0

        if "limit" in request.form:
            try:
                limit = int(request.form['limit'])
            except Exception, e:
                pass

        if "offset" in request.form:
            try:
                offset = int(request.form['offset'])
            except Exception, e:
                pass
Exemple #5
0
def get_movies(order, direction, minvotes, maxvotes, minrating, maxrating, total_count=20, cursor=None):
    key = "[movies]%s;%s;%s;%s;%s;%s;%s;%s" % (order, direction, minvotes, maxvotes, minrating, maxrating, total_count, cursor)
    movies = memcache.get(key, namespace="movies")
    #if movies:
    #    l.info('Memcache hit in movies')
    #    return movies


    q = Movie.all()

    l.info((order, direction, minvotes, maxvotes, minrating, maxrating))
    maxrating = int(maxrating*10)
    minrating = int(minrating*10)
    if maxvotes > 200000: maxvotes = ()

    prefix = ''
    if direction == 'descending': prefix = '-'

    #if minvotes > 0: q = q.filter('imdbvotes >=', minvotes)
    #if maxvotes < 300000: q = q.filter('imdbvotes <=', maxvotes)

    #if minrating > 0: q = q.filter('imdbrating >=', minrating)
    #if maxrating < 100: q = q.filter('imdbrating <=', minrating)

    if order == 'age': q = q.order(prefix+'nzbdate')
    if order == 'name': q = q.order(prefix+'rlsname')
    if order == 'imdbrating': q = q.order(prefix+'imdbrating')
    if order == 'imdbvotes': q = q.order(prefix+'imdbvotes')

    if cursor: q = q.with_cursor(cursor)

    #tm = {}
    tm = []
    i = []
    count = 0
    date = None
    for m in q:
        if count == 20: break
        if not m.imdbrating: m.imdbrating = 0
        if not m.imdbvotes: m.imdbvotes = 0

        #How nice, a table scan :(
        if not (minrating <= m.imdbrating <= maxrating and minvotes <= m.imdbvotes <= maxvotes):
          continue
        else:
          count += 1

        if m.imdbid == None:
           m.imdbid = re.search('tt\d{7}', m.imdblink).group(0)
           #m.put()

        template_movie = {'type': 'movie'}
        #template_movie['counter'] = count
        template_movie['nzblink'] = m.nzblink
        template_movie['rlsname'] = m.rlsname
        template_movie['prettydate'] = util.pretty_date(m.nzbdate)
        template_movie['imdblink'] = m.imdblink
        template_movie['rtlink'] = 'http://www.rottentomatoes.com/alias?type=imdbid&s=%s' % m.imdbid[2:]

        if m.imdbinfo:
            template_movie['imdbinfo?'] = True
            template_movie['rating'] = m.imdbinfo.rating / 10.0
            template_movie['votes'] = m.imdbinfo.votes
            template_movie['imdbinfo'] = m.imdbinfo
            if m.imdbinfo.covers.count(1):
              template_movie['cover'] = '/serve/%s' % m.imdbinfo.covers[0].blobkey.key()
              i.append(template_movie)
        else:
            template_movie['imdbinfo?'] = False

        if not date == m.nzbdate.date():
            date = m.nzbdate.date()
            tm.append({'d': date, 'day': date.strftime('%A, %d %B %Y'), 'type': 'date'})
        #if not date in tm: tm[date] = {'d': date, 'day': date.strftime('%A, %d %B %Y'), 'movies': []}
        tm.append(template_movie)
        if count >= total_count: break

    movies = (tm, i, q.cursor())
    memcache.set(key, movies, namespace='movies')
    return movies
Exemple #6
0
def home():
    
    q = Movie.all()
    q.order("-votes")
    
    return render_template('home.html', movies=q.run(limit=11), form=SearchForm(), image_path=settings.IMAGE_PATH, total=q.count(), offset=0)