示例#1
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_select_movie_to_watch(self):
     watchlist.add_movie(Movie("Moana", 2016))
     assert watchlist.first_movie_in_watchlist() == Movie("Moana", 2016)
     assert watchlist.select_movie_to_watch(0) == Movie(
         "Moana", 2016)  #when movie in watchlist
     assert watchlist.select_movie_to_watch(
         watchlist.size() + 2) == None  #when movie not in watchlist
 def test_no_first_movie_in_watchlist(self):
     watchlist.add_movie(Movie("Moana", 2016))
     assert watchlist.first_movie_in_watchlist() == Movie(
         "Moana", 2016)  #with_first_movie
     watchlist.remove_movie(Movie("Moana", 2016))
     assert watchlist.first_movie_in_watchlist(
     ) is None  #with_no_first_movie
示例#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)
示例#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)
def dict_to_movie(dict):
    movie = Movie(dict.title, dict.release_year, dict.id)
    movie.add_actor(dict.actors)
    for genre in dict.genre:
        movie.add_genre(genre)
    movie.director = dict.director
    movie.runtime_minutes = dict.runtime_minutes
    movie.description = dict.description
    return movie
示例#7
0
def load_articles_and_tags(data_path: str, repo: MemoryRepository):
    tags = dict()

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

        article_key = int(data_row[0])
        number_of_tags = len(data_row) - 6
        article_tags = data_row[-number_of_tags:]

        # Add any new tags; associate the current article with tags.
        for tag in article_tags:
            if tag not in tags.keys():
                tags[tag] = list()
            tags[tag].append(article_key)
        del data_row[-number_of_tags:]

        # Create Article object.
        article = Movie(
            date=date.fromisoformat(data_row[1]),
            title=data_row[2],
            first_para=data_row[3],
            hyperlink=data_row[4],
            image_hyperlink=data_row[5],
            id=article_key
        )

        # Add the Article to the repository.
        repo.add_article(article)
示例#8
0
def browse_movies_actor():
    q_name = request.args.get("actor")
    q_page = request.args.get("page")

    if q_page is None:
        q_page = 0
    elif int(q_page) < 0:
        q_page = 0
    else:
        q_page = int(q_page)

    mv_list_raw = services.search(q_name, "actor", repo.repository_instance)
    # print(mv_list_raw)
    mv_list = mv_list_raw[(q_page * 8):(q_page * 8 + 8)]

    prev_page_url = url_for('browse_bp.browse_movies_actor',
                            actor=q_name,
                            page=q_page - 1)
    next_page_url = url_for('browse_bp.browse_movies_actor',
                            actor=q_name,
                            page=q_page + 1)

    while len(mv_list) < 8:
        mv_list.append(Movie(title="...", year=2016))

    # gen pages
    return render_template('content/browse.html',
                           mv_list=mv_list,
                           prev_year_url="prev_year_url",
                           next_year_url="next_year_url",
                           prev_page_url=prev_page_url,
                           next_page_url=next_page_url,
                           featured_title="Showing results for actor: " +
                           q_name,
                           type="actor")
示例#9
0
def test_actor_construction(actor):
    assert actor.actor_full_name == 'Chris Pratt'

    for movie in actor.actor_movie:
        assert False

    assert not actor.is_applied_to(Movie(None, None))
示例#10
0
def test_genre_construction(genre):
    assert genre.genre_name == 'Action'

    for movie in genre.genre_movie:
        assert False

    assert not genre.is_applied_to(Movie(None, None))
def test_repository_can_add_movie(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    number_of_movies = repo.get_number_of_movies()

    new_movie_id = number_of_movies + 1

    movie = Movie('Parasite', 2019, new_movie_id)
    repo.add_movie(movie)

    assert repo.get_movie(new_movie_id) == movie
def movie():
    return Movie(
        "Guardians of the Galaxy",
        "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.",
        2014,
        121,
        8.1,
        757074,
        333.13,
        76

    )
示例#13
0
    def get_movies_by_year(self, y) -> List[Movie]:
        target_movie = Movie(
            name=None,
            year1=y,
            rank=None,
        )
        matching_movie = list()

        try:
            for movie in self._movies:
                if movie.year == y:
                    matching_movie.append(movie)
        except ValueError:
            # No articles for specified date. Simply return an empty list.
            pass

        return matching_movie
示例#14
0
def recommend():
    import movie.home.recommandation as recommandation

    choosed = recommandation.main()

    if request.method == "POST":

        movie_name = request.form["movie_name"]
        movie_id = request.form["movie_id"]
        rtext = request.form["rtext"]
        rating = request.form["rating"]

        movie = Movie(movie_name, 1990, int(movie_id))
        review = Review(movie, rtext, int(rating))
        rc_reviews.append(review)

    return render_template("recommend.html", choosed=choosed)
示例#15
0
    def get_articles_by_date(self, target_date: date) -> List[Movie]:
        target_article = Movie(
            date=target_date,
            title=None,
            first_para=None,
            hyperlink=None,
            image_hyperlink=None
        )
        matching_articles = list()

        try:
            index = self.article_index(target_article)
            for article in self._articles[index:None]:
                if article.date == target_date:
                    matching_articles.append(article)
                else:
                    break
        except ValueError:
            # No articles for specified date. Simply return an empty list.
            pass

        return matching_articles
示例#16
0
def movie():
    return Movie('Guardians of the Galaxy', 2014)
 def test_size(self):
     watchlist.add_movie(Movie("Moana", 2016))
     watchlist.add_movie(Movie("Ice Age", 2002))
     watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
     assert watchlist.size() == 3
示例#18
0
def browse_movies_year():
    # query year
    q_year = request.args.get('year')
    q_page = request.args.get('page')

    if q_year is None:
        q_year = 2016
    else:
        q_year = int(q_year)

    if q_page is None:
        q_page = 0
    elif int(q_page) < 0:
        q_page = 0
    else:
        q_page = int(q_page)

    prev_year_url = None
    next_year_url = None

    current_year_raw = services.movie_filter_year(q_year,
                                                  repo.repository_instance)
    current_year = current_year_raw[(q_page * 8):(q_page * 8 + 8)]

    while len(current_year) < 8:
        current_year.append(Movie(title="...", year=2016))

    # print(current_year_raw)
    # print(current_year)
    # previous_year = services.movie_filter_year(q_year - 1, repo.repository_instance)
    # next_year = services.movie_filter_year(q_year + 1, repo.repository_instance)

    # need to check year valid

    if q_year + 1 > 2016:
        next_year_url = url_for('browse_bp.browse_movies_year',
                                year=2016,
                                page=0)
        prev_year_url = url_for('browse_bp.browse_movies_year',
                                year=(q_year - 1),
                                page=0)
    elif q_year - 1 < 2006:
        next_year_url = url_for('browse_bp.browse_movies_year',
                                year=(q_year + 1),
                                page=0)
        prev_year_url = url_for('browse_bp.browse_movies_year',
                                year=2006,
                                page=0)
    else:
        prev_year_url = url_for('browse_bp.browse_movies_year',
                                year=(q_year - 1),
                                page=0)
        next_year_url = url_for('browse_bp.browse_movies_year',
                                year=(q_year + 1),
                                page=0)

    prev_page_url = url_for('browse_bp.browse_movies_year',
                            year=q_year,
                            page=q_page - 1)
    next_page_url = url_for('browse_bp.browse_movies_year',
                            year=q_year,
                            page=q_page + 1)

    # gen pages
    return render_template('content/browse.html',
                           mv_list=current_year,
                           prev_year_url=prev_year_url,
                           next_year_url=next_year_url,
                           prev_page_url=prev_page_url,
                           next_page_url=next_page_url,
                           featured_title="Showing Year " + str(q_year),
                           type="year")
示例#19
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)
示例#20
0
def review():
    m = Movie('matrix', 1998, 1)
    return Review(m, 'good movie!', 5)
示例#21
0
def movie():
    return Movie('matrix', 1998, 1)
示例#22
0
def dict_to_movie(dict):
    movie = Movie(dict.title, dict.year, dict.rank)
    # Note there's no comments or tags.
    return movie
示例#23
0
 def add_movie(self, movie: Movie):
     movie.id = len(self._movies) + 1
     self._movies.append(movie)
     self._movies_title.append(movie)
示例#24
0
def test_movie_less_than_operator():
    movie_1 = Movie('Guardians of the Galaxy', 2014)

    movie_2 = Movie('Prometheus', 2012)

    assert movie_1 < movie_2
示例#25
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)
示例#26
0
def make_movie():
    movie = Movie('Moana', movie_year)
    return movie
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie(name='The Great Wall',year1=2016,rank=6)
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(6) is movie
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
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie('Moana', 2016)
    in_memory_repo.add_movie(movie)
    assert in_memory_repo.get_movie(1001) is movie
def make_movie(new_movie_release_year):
    movie = Movie('The Promised Neverland', new_movie_release_year)
    return movie