Пример #1
0
def dict_to_movie(dict):
    movie = Movie(dict.title, dict.year)
    movie.id = dict.id
    movie.description = dict.descrption
    movie.reviews = dict.reviews
    movie.director = dict.director
    movie.acotrs = dict.actors
    movie.genres = dict.genres
    return movie
Пример #2
0
def load_movies_and_genres(data_path: str, repo: MemoryRepository):
    genres_list = []
    file_path = os.path.join(data_path, 'image_link.json')
    f = open(file_path, 'r')
    image_link = json.load(f)
    for data_row in read_csv_file(os.path.join(data_path,
                                               'Data1000Movies.csv')):
        movie_title = data_row[1]
        movie_year = int(data_row[6])
        geners = data_row[2].split(',')
        director = data_row[4]
        actors = data_row[5].split(',')
        description = data_row[3]
        runtime_minutes = int(data_row[7])
        genres_list.extend(geners)
        genres_list = list(set(genres_list))

        # Add any new tags; associate the current article with tags.

        # Create Article object.
        movie = Movie(title=movie_title, release_year=movie_year)
        if movie_title in image_link.keys():
            movie.image_hyperlink = image_link[movie_title]
        else:
            movie.image_hyperlink = 'https://m.media-amazon.com/images/M/MV5BNTY3NTY3ODAzOF5BMl5BanBnXkFtZTcwMTI4MDQyOA@@._V1_SX300.jpg'
        if movie.image_hyperlink == None:
            movie.image_hyperlink = 'https://m.media-amazon.com/images/M/MV5BNTY3NTY3ODAzOF5BMl5BanBnXkFtZTcwMTI4MDQyOA@@._V1_SX300.jpg'

        movie.director = Director(director)
        movie.runtime_minutes = runtime_minutes
        movie.description = description
        movie.comments.append("This is first comments")
        for actor in actors:
            movie.add_actor(Actor(actor))
        for gener in geners:
            movie.add_genre(Genre(gener))

        # Add the Article to the repository.
        repo.add_movie(movie)

    for gener_name in genres_list:
        repo.add_genre(Genre(gener_name))