当前位置: 首页>>代码示例>>Python>>正文


Python Movie.get_by_id方法代码示例

本文整理汇总了Python中models.Movie.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.get_by_id方法的具体用法?Python Movie.get_by_id怎么用?Python Movie.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Movie的用法示例。


在下文中一共展示了Movie.get_by_id方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tastes_movies_list

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def get_tastes_movies_list(user, page=0):
    """
    Get a readable taste movies list.
    :param user: user
    :type user: Models.User
    :return: list of tastes
        {"code": 0, "data": {"tastes": [{"idIMDB": id,"originalTitle": original_title, "poster": poster_url}],
        "type": type, "userId": user_id}
    :rtype: JSON
    """
    tastes_movies_id = user.tastes_movies

    movies = []

    for taste_movie_id in tastes_movies_id:
        taste_movie = TasteMovie.get_by_id(taste_movie_id.id())  # Get taste
        if taste_movie.taste >= 1 and taste_movie.added:
            movie_id = taste_movie.movie.id()  # Get movie id from taste
            movie = Movie.get_by_id(movie_id)  # Get movie by id

            movies.append({"idIMDB": movie_id,
                       "originalTitle": movie.original_title.encode('utf-8') if movie.original_title is not None else None,
                       "title": movie.title.encode('utf-8') if movie.title is not None else None,
                       "tasted": 1,
                       "poster": movie.poster})

    return jsonify(code=0, data={"userId": user.key.id(), "type": "movie", "tastes": movies})
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:29,代码来源:api.py

示例2: add_movie_tastes

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def add_movie_tastes(user_id, movie_id, taste):

        taste = float(taste)
        user = User.get_by_id(user_id)
        movie = Movie.get_by_id(movie_id)
        for actor in movie.actors:
            artist = Artist.get_by_id(actor.id())
            user.add_taste_artist(artist, ACTOR_WEIGHT * taste)

        for director in movie.directors:
            artist = Artist.get_by_id(director.id())
            user.add_taste_artist(artist, DIRECTOR_WEIGHT * taste)

        for writer in movie.writers:
            artist = Artist.get_by_id(writer.id())
            user.add_taste_artist(artist, WRITER_WEIGHT * taste)

        for genre in movie.genres:
            user.add_taste_genre(genre, GENRE_WEIGHT * taste)

        user.remove_proposal()
        user.put()
        taskqueue.add(url='/api/proposal/' + user.key.id(), method='GET')


        return 'OK'
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:28,代码来源:task.py

示例3: movies_vote

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
 def movies_vote(self, request):
     """Exposes an API endpoint to insert the new votes from the user
     Args:
         request: A list of the movies the user currently likes and cast a vote.
     Returns:
         A void message if everthing goes well or an error.
     """
     #get jwt and validates if user exists
     selected_user = self.validate_jwtoken(self.request_state)
     
     list_of_voted_movies_query = MovieRankingUser.query(MovieRankingUser.user==selected_user.key).fetch()
     for user_movie_relation in list_of_voted_movies_query:
         current_movie = Movie.query(Movie.key==user_movie_relation.movie).get()
         current_counter = current_movie.number_of_users_who_voted
         current_movie.number_of_users_who_voted = current_counter - 1
         current_movie.put()
         user_movie_relation.key.delete()
         
     for voted_movie in request.voted_movies:
         current_movie = Movie.get_by_id(voted_movie.movie_identifier)
         current_counter = current_movie.number_of_users_who_voted
         current_movie.number_of_users_who_voted = current_counter + 1
         new_movie_user_vote = MovieRankingUser(user=selected_user.key,movie=current_movie.key)
         current_movie.put()
         new_movie_user_vote.put()
     return VoteResponse(status_msg='Vote casted with success.')
开发者ID:xmaps,项目名称:movie-ranking-test,代码行数:28,代码来源:movie_ranking_api.py

示例4: untaste_movie

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def untaste_movie(user_id, movie_id):
            movie = Movie.get_by_id(movie_id)
            user = User.get_by_id(user_id)

            for actor in movie.actors:
                artist = Artist.get_by_id(actor.id())
                taste_artist = TasteArtist.get_by_id(actor.id() + user.key.id())

                if taste_artist is not None:
                    taste_artist.update_taste(-ACTOR_WEIGHT)
                else:
                    user.add_taste_artist(artist, -ACTOR_WEIGHT)

                if taste_artist.taste == 0:
                    user.remove_taste_artist(artist)

            for director in movie.directors:
                artist = Artist.get_by_id(director.id())
                taste_artist = TasteArtist.get_by_id(director.id() + user.key.id())

                if taste_artist is not None:
                    taste_artist.update_taste(-DIRECTOR_WEIGHT)
                else:
                    user.add_taste_artist(artist, -DIRECTOR_WEIGHT)

                if taste_artist.taste == 0:
                    user.remove_taste_artist(artist)

            for writer in movie.writers:
                artist = Artist.get_by_id(writer.id())
                taste_artist = TasteArtist.get_by_id(writer.id() + user.key.id())

                if taste_artist is not None:
                    taste_artist.update_taste(-WRITER_WEIGHT)
                else:
                    user.add_taste_artist(artist, -WRITER_WEIGHT)

                if taste_artist.taste == 0:
                    user.remove_taste_artist(artist)

            for genre in movie.genres:
                taste_genre = TasteGenre.get_by_id(genre + user.key.id())

                if taste_genre is not None:
                    taste_genre.update_taste(-GENRE_WEIGHT)
                else:
                    user.add_taste_genre(genre, -GENRE_WEIGHT)

                if taste_genre.taste == 0:
                    user.remove_taste_genre(genre)

            user.remove_proposal()
            user.put()
            taskqueue.add(url='/api/proposal/' + user.key.id(), method='GET')

            return 'OK'
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:58,代码来源:task.py

示例5: get_or_retrieve_by_id

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def get_or_retrieve_by_id(id_imdb):
    """
    This function check if the id is a valid IMDb id and in this case get or retrieve the correct entity.
    :param id_imdb: a valid IMDb id
    :type id_imdb: string
    :return: A model instance
    :rtype Artist or Movie model
    """

    artist = re.compile('nm\d{7}$')
    movie = re.compile('tt\d{7}$')

    if artist.match(id_imdb):  # It is an artist's id
        artist = Artist.get_by_id(id_imdb)  # Find artist by id
        if artist is None:

            try:
                artist_key = retrieve_artist_from_id(id_imdb)  # Retrieve if is not in the datastore
            except RetrieverError as retriever_error:
                raise InternalServerError(retriever_error)

            artist = Artist.get_by_id(artist_key.id())  # Get artist by id

        return artist
    elif movie.match(id_imdb):  # It is a movie's id
        movie = Movie.get_by_id(id_imdb)  # Find movie by id
        if movie is None:

            try:
                movie_key = retrieve_movie_from_id(id_imdb)  # Retrieve if is not in the datastore
            except RetrieverError as retriever_error:
                raise InternalServerError(retriever_error)

            movie = Movie.get_by_id(movie_key.id())  # Get movie by id

        return movie
    else:
        new_movie = Movie().get_by_id(id_imdb)
        if new_movie != None:
            return new_movie
        else:
            raise InternalServerError(id_imdb + " is not a valid IMDb id or film.TV id")
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:44,代码来源:api.py

示例6: get_watched_movies_list

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def get_watched_movies_list(user, page=0):
    """
    Get a readable watched movie list.
    :param user: user
    :type user: Models.User
    :return: list of watched movies
        {"code": 0, "data": {"movies": [{"idIMDB": id,"originalTitle": original_title, "poster": poster_url,
        "date": date}],"userId": user_id, "prevPage": prevPage, "nextPage": nextPage}
    :rtype: JSON
    """

    watched_movies_id = user.watched_movies  # Get all taste_artists' keys

    movies = []

    if (page + 1)*10 > len(watched_movies_id):  # Finding max element in page
        last_elem = len(watched_movies_id)
    else:
        last_elem = (page + 1)*10

    if (page + 1)*10 < len(watched_movies_id):  # Preparing url for next page
        next_page = str(page + 1)
        next_page_url = '/api/watched/' + user.key.id() + '/' + next_page
    else:
        next_page_url = None

    if page > 0:  # Preparing url for prev page
        prev_page = str(page - 1)
        prev_page_url = '/api/watched/' + user.key.id() + '/' + prev_page
    else:
        prev_page_url = None

    for i in range(page * 10, last_elem):  # Preparing JSON with list of movies watched for current page
        watched_movie_id = watched_movies_id[i].id()
        watched_movie = Movie.get_by_id(watched_movie_id)  # Get movie

        date_watched_movie = user.date_watched[i]  # Get date

        taste_movie = TasteMovie.get_by_id(watched_movie_id + user.key.id())  # Get taste

        movies.append({"idIMDB": watched_movie.key.id(),
                       "originalTitle": watched_movie.original_title.encode('utf-8') if watched_movie.original_title is not None else watched_movie.title.encode('utf-8'),
                       "title": watched_movie.title.encode('utf-8') if watched_movie.title is not None else watched_movie.original_title.encode('utf-8'),
                       "poster": watched_movie.poster,
                       "date": date_watched_movie.strftime('%d-%m-%Y'),
                       "tasted": 1 if taste_movie is not None else 0})

    return jsonify(code=0, data={"userId": user.key.id(), "watched": movies,
                                 "nextPage": next_page_url, "previousPage": prev_page_url})
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:51,代码来源:api.py

示例7: movies_get

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
 def movies_get(self, request):
     """Exposes an API endpoint to obtain the details of a Movie
     Args:
         request: Id of the movie
     Returns:
         An Instance containing the Movie Details
     """
     #get jwt and validates if user exists
     self.validate_jwtoken(self.request_state)
     
     selected_movie = Movie.get_by_id(request.id)
     if selected_movie is None:
         message = 'No movie with the id "%s" exists.' % request.id
         raise endpoints.NotFoundException(message)
     list_of_users_voted_movies_query = MovieRankingUser.query(MovieRankingUser.movie==selected_movie.key).fetch()
     list_of_users_voted = [RankingUser.query(RankingUser.key==user_movie_relation.user).get().to_simpler_message() for user_movie_relation in list_of_users_voted_movies_query]
     return selected_movie.to_message(users_who_voted=list_of_users_voted)
开发者ID:xmaps,项目名称:movie-ranking-test,代码行数:19,代码来源:movie_ranking_api.py

示例8: generate_movies

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def generate_movies(user, page=0):

    tastes_movies_id = user.tastes_movies
    movies = []

    for i in range(page, len(tastes_movies_id)):
        taste_movie_id = tastes_movies_id[i]
        taste_movie = TasteMovie.get_by_id(taste_movie_id.id())  # Get taste

        movie_id = taste_movie.movie.id()  # Get movie id from taste
        movie = Movie.get_by_id(movie_id)  # Get movie by id

        movies.append({"idIMDB": movie_id,
                       "originalTitle": movie.original_title.encode('utf-8') if movie.original_title is not None else movie.title.encode('utf-8'),
                       "title": movie.title.encode('utf-8') if movie.title is not None else movie.original_title.encode('utf-8'),
                       "tasted": 1,
                       "poster": movie.poster})

    return movies
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:21,代码来源:api.py

示例9: get_tastes_list

# 需要导入模块: from models import Movie [as 别名]
# 或者: from models.Movie import get_by_id [as 别名]
def get_tastes_list(user):
    """
    Get a readable taste artists list.
    :param user: user
    :type user: Models.User
    :return: list of tastes
        {"code": 0, "data": {"tastes": [{"idIMDB": id,"originalTitle": original_title, "poster": poster_url}],
        "type": type, "userId": user_id}
    :rtype: JSON
    """
    # TODO: improve it, replace with function...

    if user.tastesInconsistence is not True:
        logging.info("tastes in memory")
        return jsonify(code=0, data=user.tastesJson)

    logging.info("rebuiling tastes")

    tastes_artists_id = user.tastes_artists  # Get all taste_artists' keys
    artists = []

    for taste_artist_id in tastes_artists_id:
        taste_artist = TasteArtist.get_by_id(taste_artist_id.id())  # Get taste

        if taste_artist is None:
            logging.error("taste_artist is None")
            continue

        if taste_artist.taste >= 0.99 and taste_artist.added:
            artist_id = taste_artist.artist.id()  # Get artist id from taste
            artist = Artist.get_by_id(artist_id)  # Get artist by id

            artists.append({"idIMDB": artist_id,
                            "name": artist.name.encode('utf-8') if artist.name is not None else None,
                            "tasted": 1,
                            "photo": artist.photo})

    tastes_movies_id = user.tastes_movies

    movies = []

    for taste_movie_id in tastes_movies_id:
        taste_movie = TasteMovie.get_by_id(taste_movie_id.id())  # Get taste

        if taste_movie is None:
            logging.error("taste_movie is None")
            continue
        if taste_movie.taste >=1 and taste_movie.added :
            movie_id = taste_movie.movie.id()  # Get movie id from taste
            movie = Movie.get_by_id(movie_id)  # Get movie by id

            movies.append({"idIMDB": movie_id,
                       "originalTitle": movie.original_title.encode('utf-8') if movie.original_title is not None else movie.title.encode('utf-8'),
                       "title": movie.title.encode('utf-8') if movie.title is not None else movie.original_title.encode('utf-8'),
                       "tasted": 1,
                       "poster": movie.poster})

    tastes_genres_id = user.tastes_genres

    genres = []

    for taste_genre_id in tastes_genres_id:
        taste_genre = TasteGenre.get_by_id(taste_genre_id.id())  # Get taste
        if taste_genre is None:
            logging.error("taste_genre is None")
            continue

        # TODO: not use object, use a simple list
        if taste_genre.taste >= 0.99 and taste_genre.added :
            genres.append({"name": taste_genre.genre,
                           "tasted": 1})

    dataJson = {"userId": user.key.id(),
                         "type": "all",
                         "tastes": {"artists": artists,
                                    "movies": movies,
                                    "genres": genres}}

    user.tastesJson = dataJson
    user.tastesInconsistence = False
    user.put()

    return jsonify(code=0, data=dataJson)
开发者ID:PRIMETIME4U,项目名称:PRIMETIME4U-server,代码行数:85,代码来源:api.py


注:本文中的models.Movie.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。