def load_movies():
    data_path = os.path.join("movie", "adapters", "data")
    # print(data_path, '#'*10)
    moive_list = []
    director1 = Director("Joss Whedon")
    director2 = Director("Anthony Russo")

    actor1 = Actor("Robert Downey")
    actor2 = Actor("Chris Evans")

    genre1 = Genre("fiction")
    genre2 = Genre("action")
    for data_row in read_csv_file(os.path.join(data_path, "news_movies.csv")):
        # print(data_row, '#'*5)
        movie_key = int(data_row[0])

        # Create Moive object.
        movie = Movie(
            title=data_row[1],
            # date=date.fromisoformat(data_row[2]),
            release_year=data_row[2],
            # image_hyperlink=data_row[5],
            id=movie_key,
        )
        # add realted director
        if movie_key == 1:
            movie.director = director1

            movie.add_actor(actor1)
            movie.add_actor(actor2)

            movie.add_genre(genre1)
            movie.add_genre(genre2)

        elif movie_key == 2:
            movie.director = director1
            movie.add_actor(actor1)
            movie.add_actor(actor2)

            movie.add_genre(genre1)
            movie.add_genre(genre2)
        elif movie_key == 3:

            movie.director = director2
            movie.add_actor(actor1)
            movie.add_actor(actor2)

            movie.add_genre(genre1)
            movie.add_genre(genre2)
        elif movie_key == 4:
            movie.director = director2
            movie.add_actor(actor1)
            movie.add_actor(actor2)

            movie.add_genre(genre1)
            movie.add_genre(genre2)

        moive_list.append(movie)
        print(movie, "in MemoryRepository", movie.director)
    return moive_list
Ejemplo n.º 2
0
def load_movies_and_ids(data_path: str, repo: MemoryRepository):
    ids = dict()
    for row in read_csv_file(os.path.join(data_path, 'moviefile.csv')):
        movie = Movie(row[1], int(row[6]))
        movie.id = int(row[0])
        movie.description = row[3]
        movie.runtime_minutes = int(row[7])

        director = Director(row[4])
        repo.add_director(director)
        movie.director = director

        parsed_genres = row[2].split(',')
        for genre_string in parsed_genres:
            genre = Genre(genre_string)
            movie.add_genre(genre)
            repo.add_genre(genre)

            parsed_actors = row[5].split(',')
            for actor_string in parsed_actors:
                actor = Actor(actor_string)
                repo.add_actor(actor)
                movie.add_actor(actor)

        # Add the Movie to the repository.
        repo.add_movie(movie)
        repo.add_movie_index(movie)
def test_repository_can_add_a_genre(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    genre = Genre('WOW')
    repo.add_genre(genre)

    assert genre in repo.get_genres()
Ejemplo n.º 4
0
def read_csv_file(filename: str, repo: MemoryRepository):
    with open(filename, encoding='utf-8-sig') as infile:
        rows = csv.DictReader(infile)
        for row in rows:
            title = row['Title']
            description = row['Description']
            year = int(row['Year'])
            director = row['Director']
            D = Director(director.strip())
            genres = row['Genre'].split(',')
            movie = Movie(title, year)
            movie.director = D
            movie.description = description
            for genre in genres:
                G = Genre(genre.strip())
                repo.add_genre(G)
                movie.genres.append(G)
            repo.add_director(D)
            actors = row['Actors'].split(',')
            for actor in actors:
                A = Actor(actor.strip())
                repo.add_actor(A)
                movie.actors.append(A)
            #
            runtime = int(row['Runtime (Minutes)'])
            movie.runtime_minutes = runtime
            repo.add_movie(movie)
Ejemplo n.º 5
0
def load_all(file_name: str, repo: MemoryRepository):
    with open(file_name, mode='r', encoding='utf-8-sig') as csvfile:
        movie_file_reader = csv.DictReader(csvfile)

        for row in movie_file_reader:
            movie = Movie(row['Title'], int(row['Year']))
            movie.description = row['Description']
            movie.runtime_minutes = int(row['Runtime (Minutes)'])

            director = Director(row['Director'])
            repo.add_director(director)
            movie.director = director

            parsed_genres = row['Genre'].split(',')
            for genre_string in parsed_genres:
                genre = Genre(genre_string)
                repo.add_genre(genre)
                movie.add_genre(genre)

            parsed_actors = row['Actors'].split(',')
            for actor_string in parsed_actors:
                actor = Actor(actor_string)
                repo.add_actor(actor)
                movie.add_actor(actor)

            repo.add_movie(movie)
Ejemplo n.º 6
0
def test_loading_of_genred_movie(empty_session):
    movie_key = insert_movie(empty_session)
    genre_keys = insert_genres(empty_session)
    insert_movie_genre_associations(empty_session, movie_key, genre_keys)

    movie = empty_session.query(Movie).get(movie_key)
    genre = Genre('Thriller')
    assert movie.has_genre('Thriller')
Ejemplo n.º 7
0
def test_repository_can_retrieve_movie(in_memory_repo):
    movie = in_memory_repo.get_movie(1)

    # Check that the Article has the expected title.
    assert movie.title == 'Guardians of the Galaxy'

    # Check that the Article is commented as expected.
    review_one = [review for review in movie.reviews if review.review_text == 'Oh no, COVID-19 has hit New Zealand'][0]
    review_two = [review for review in movie.reviews if review.review_text == 'Yeah Freddie, bad news'][0]

    assert review_one.user.user_name == 'fmercury'
    assert review_two.user.user_name == "thorke"

    # Check that the Article is tagged as expected.
    assert movie.is_genred_by(Genre('Action'))
    assert movie.is_genred_by(Genre('Adventure'))
    assert movie.is_genred_by(Genre('Sci-Fi'))
    assert movie.is_acted_by(Actor('Chris Pratt'))
    assert movie.is_acted_by(Actor('Vin Diesel'))
    assert movie.is_acted_by(Actor('Bradley Cooper'))
    assert movie.is_acted_by(Actor('Zoe Saldana'))
Ejemplo n.º 8
0
def test_repository_can_retrieve_movie(in_memory_repo):
    movie = in_memory_repo.get_movie(1)

    # Check that the movie has the expected title.
    assert movie.title == 'Guardians of the Galaxy'

    # Check that the Movie is reviewed as expected.
    review_one = [
        review for review in movie.reviews
        if review.review_text == "I love this movie"
    ][0]
    review_two = [
        review for review in movie.reviews
        if review.review_text == "Master piece!"
    ][0]

    assert review_one.user.username == 'fmercury'
    assert review_two.user.username == "thorke"

    # Check that the Movie has the expected genre.
    assert movie.has_genre(Genre('Action'))
    assert movie.has_genre(Genre('Adventure'))
Ejemplo n.º 9
0
def genre():
    return Genre('New Zealand')
Ejemplo n.º 10
0
def test_repository_can_add_a_tag(in_memory_repo):
    genre = Genre('Annoying')
    in_memory_repo.add_genre(genre)

    assert genre in in_memory_repo.get_genres()
Ejemplo n.º 11
0
def load_movies_and_genres(data_path: str, repo: MemoryRepository):
    genres = dict()
    actors = dict()
    directors = dict()

    for data_row in read_csv_file(os.path.join(data_path,
                                               'Data1000Movies.csv')):

        movie_key = int(data_row[0])
        movie_genres = data_row[2].split(',')
        movie_actors = data_row[5].split(',')
        movie_director = data_row[4].strip()

        for genre in movie_genres:
            genre = genre.strip()
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie_key)

        for actor in movie_actors:
            actor = actor.strip()
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie_key)

        if movie_director not in directors.keys():
            directors[movie_director] = list()
        directors[movie_director].append(movie_key)

        movie = Movie(title=data_row[1],
                      description=data_row[3],
                      year=data_row[6],
                      runtime_minutes=data_row[7],
                      rating=data_row[8],
                      votes=data_row[9],
                      revenue_millions=data_row[10],
                      meta_score=data_row[11],
                      id=movie_key)

        repo.add_movie(movie)

    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for movie_id in genres[genre_name]:
            movie = repo.get_movie(movie_id)
            make_genre_association(movie, genre)
        repo.add_genre(genre)

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for movie_id in actors[actor_name]:
            movie = repo.get_movie(movie_id)
            make_actor_association(movie, actor)
        repo.add_actor(actor)

    for director_name in directors.keys():
        director = Director(director_name)
        for movie_id in directors[director_name]:
            movie = repo.get_movie(movie_id)
            make_director_association(movie, director)
        repo.add_director(director)
Ejemplo n.º 12
0
def make_genre():
    genre = Genre("Newest")
    return genre
Ejemplo n.º 13
0
def load_movies_and_genres_and_actors_and_directors(data_path: str, repo: MemoryRepository):
    genres = dict()
    actors = dict()
    directors = dict()
    for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):

        movie_key = int(data_row[0])
        number_of_genres = 2
        movie_genres = sorted(data_row[number_of_genres].strip().split(','))
        number_of_actors = 5
        movie_actors = sorted(data_row[number_of_actors].strip().split(','))
        number_of_directors = 4
        movie_directors = sorted(data_row[number_of_directors].strip().split(','))

        # Add any new tags; associate the current article with tags.
        for genre in movie_genres:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie_key)
        # del data_row[number_of_genres]

        for actor in movie_actors:
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie_key)

        for director in movie_directors:
            if director not in directors.keys():
                directors[director] = list()
            directors[director].append(movie_key)

        # Create Article object.
        movie = Movie(
            name=data_row[1],
            year1=int(data_row[6]),
            rank=int(data_row[0])
        )

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

    # Create Tag objects, associate them with Articles and add them to the repository.
    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for movie_rank in genres[genre_name]:
            movie = repo.get_movie(movie_rank)
            make_genre_association(movie, genre)
        repo.add_genre(genre)

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for movie_rank in actors[actor_name]:
            movie = repo.get_movie(movie_rank)
            make_actor_association(movie, actor)
        repo.add_actor(actor)

    for director_name in directors.keys():
        director = Director(director_name)
        for movie_rank in directors[director_name]:
            movie = repo.get_movie(movie_rank)
            make_director_association(movie, director)
        repo.add_director(director)
Ejemplo n.º 14
0
def genre():
    return Genre('Action')
Ejemplo n.º 15
0
def test_repository_can_add_a_genre(in_memory_repo):
    genre = Genre('Crime')
    in_memory_repo.add_genre(genre)

    assert genre in in_memory_repo.get_genre()