def test_select_movie_to_watch(watchlist):
    watchlist = WatchList()
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    assert watchlist.select_movie_to_watch(2) == Movie(
        "Guardians of the Galaxy", 2012)
Пример #2
0
 def test_dual_new_release_statement(self):
     fred = Customer("Fred")
     fred.add_rental(Rental(Movie("The Cell", Movie.NEW_RELEASE), 3))
     fred.add_rental(Rental(Movie("The Tigger Movie", Movie.NEW_RELEASE),
                            3))
     assert fred.statement(
     ) == "Rental Record for Fred\n\tThe Cell\t9.0\n\tThe Tigger Movie\t9.0\nYou owed 18.0\nYou earned 4 frequent renter points\n"
def test_iterator(watchlist):
    watchlist = WatchList()
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    temp = iter(watchlist)
    assert next(temp) == Movie("Moana", 2016)
def test_given(watchlist):
    watchlist = WatchList()
    assert watchlist.size() == 0
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    assert watchlist.first_movie_in_watchlist() == Movie("Moana", 2016)
Пример #5
0
    def parse(self, text):
        """
		This method takes a movie script (str) as an input, and returns an instance of
		the Movie class, representing the movie.
		"""
        # Try to retrieve the character list
        characters = self._get_characters(text)

        # if there are less than the minimum number of characters, special case
        if len(characters) < self.minimum_characters:
            # identify special case stereotype
            characters = self._special_characters(text)

        # retrieve metadata
        title = self.get_title(text)
        author = self.get_author(text)
        genre = self.get_genre(text)

        # if it still doesn't work, warn user
        if len(characters) < self.minimum_characters:
            fix_string = "Please check the original file's formatting, or add a special case in ScriptParser's _special_characters() method."
            print("The script %s couldn't be parsed. %s" % (title, fix_string))
            error_movie = Movie(
                title, author, genre,
                "This script couldn't be parsed. %s" % fix_string)
            return error_movie
        else:
            # return instance of Movie
            movie = Movie(title, author, genre, characters)
            return movie
Пример #6
0
def test_remove_movie(watchlist):
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    watchlist.remove_movie(Movie("Moana", 2016))
    size = watchlist.size()

    assert size == 2
Пример #7
0
 def test_multiple_regular_statement(self):
     fred = Customer("Fred")
     fred.add_rental(
         Rental(Movie("Plan 9 from Outer Space", Movie.REGULAR), 1))
     fred.add_rental(Rental(Movie("8 1/2", Movie.REGULAR), 2))
     fred.add_rental(Rental(Movie("Eraserhead", Movie.REGULAR), 3))
     assert fred.statement(
     ) == "Rental Record for Fred\n\tPlan 9 from Outer Space\t2.0\n\t8 1/2\t2.0\n\tEraserhead\t3.5\nYou owed 7.5\nYou earned 3 frequent renter points\n"
Пример #8
0
def test_find_index(watchlist):
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    out_of_bound = watchlist.select_movie_to_watch(4)
    inbound = watchlist.select_movie_to_watch(0)

    assert inbound == Movie("Moana", 2016)
    assert out_of_bound is None
Пример #9
0
def test_add_movie(watchlist):
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    first_movie = watchlist.first_movie_in_watchlist()
    size = watchlist.size()

    assert first_movie == Movie("Moana", 2016)
    assert size == 3
Пример #10
0
 def test_statement(self):
     tom = Customer("Tom")
     tom.add_rental(Rental(Movie("Shutter Island", Movie.REGULAR), 5))
     tom.add_rental(Rental(Movie("Inception", Movie.REGULAR), 3))
     tom.add_rental(Rental(Movie("The Shining", Movie.REGULAR), 9))
     self.assertEqual(
         tom.statement(),
         "Rental Record for Tom\n\tShutter Island\t6.5\n\tInception\t3.5\n\tThe Shining\t12.5\nAmount owed is 22.5\nYou earned 3 frequent renter points"
     )
Пример #11
0
 def test_statement(self):
     tom = Customer("Tom")
     tom.add_rental(Rental(Movie("Shutter Island", Movie.REGULAR), 5))
     tom.add_rental(Rental(Movie("Inception", Movie.REGULAR), 3))
     tom.add_rental(Rental(Movie("The Shining", Movie.REGULAR), 9))
     self.assertEqual(
         tom.html_statement(),
         "<h1>Rentals for <em>Tom</em></h1><p>\nShutter Island: 6.5<br>\nInception: 3.5<br>\nThe Shining: 12.5<br>\n<p>You owe <em>22.5</em></p>\nOn this rental you earned <em>3</em> frequent renter points<p>"
     )
def test_iterator_out_of_bound(watchlist):
    watchlist = WatchList()
    watchlist.add_movie(Movie("Moana", 2016))
    watchlist.add_movie(Movie("Ice Age", 2002))
    watchlist.add_movie(Movie("Guardians of the Galaxy", 2012))
    temp = iter(watchlist)
    next(temp)
    next(temp)
    next(temp)
    with pytest.raises(IndexError):
        next(temp)
Пример #13
0
def read_movie(line):
    """
    -------------------------------------------------------
    Creates and returns a Movie object from a line of formatted string data.
    Use: movie = read_movie(line)
    -------------------------------------------------------
    Parameters:
        line - a vertical bar-delimited line of movie data in the format
          title|year|director|rating|genre codes (str)
    Returns:
        movie - a Movie object based upon the data from line (Movie)
    -------------------------------------------------------
    """
    movie_list = line.split("|")

    title = movie_list[0]
    year = int(movie_list[1])
    director = movie_list[2]
    rating = float(movie_list[3])
    genres = movie_list[4].split(",")
    for i in range(len(genres)):
        genres[i] = int(genres[i])

    movie = Movie(title, year, director, rating, genres)

    return movie
Пример #14
0
def read_movie(line):
    """
    -------------------------------------------------------
    Creates and returns a Movie object from a line of formatted string data.
    Use: movie = read_movie(line)
    -------------------------------------------------------
    Parameters:
        line - a vertical bar-delimited line of movie data in the format
          title|year|director|rating|genre codes (str)
    Returns:
        movie - a Movie object based upon the data from line (Movie)
    -------------------------------------------------------
    """

    line.strip()
    data = line.split('|')
    data[4] = data[4].split(',')
    genre_list = []

    title = data[0]
    year = int(data[1])
    director = data[2]
    rating = float(data[3])

    for i in data[4]:
        genre_list.append(int(i))

    genres = genre_list

    movie = Movie(title, year, director, rating, genres)

    return movie
Пример #15
0
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)
            index = 0
            for row in movie_file_reader:
                movie = Movie(row["Title"], int(row["Year"]))
                movie.description = row["Description"]
                movie.runtime_minutes = int(row["Runtime (Minutes)"])
                self.__total_runtime_minutes += int(row["Runtime (Minutes)"])
                self.__runtime_minutes_number_of_movies += 1
                if row["Rating"] != "N/A":
                    movie.rating = float(row['Rating'])
                    self.__total_rating += float(row['Rating'])
                    self.__rating_number_of_movies += 1
                if row["Votes"] != "N/A":
                    movie.votes = int(row["Votes"])
                    self.__total_votes += int(row["Votes"])
                    self.__votes_number_of_movies += 1
                if row["Revenue (Millions)"] != "N/A":
                    movie.revenue_millions = float(row["Revenue (Millions)"])
                    self.__total_revenue_millions += float(
                        row["Revenue (Millions)"])
                    self.__revenue_millions_number_of_movies += 1
                if row["Metascore"] != "N/A":
                    movie.metascore = int(row["Metascore"])
                    self.__total_metascore += int(row["Metascore"])
                    self.__metascore_number_of_movies += 1

                self.__dataset_of_movies.append(movie)
                self.__dataset_of_directors.add(Director(row["Director"]))
                for actor in row["Actors"].split(","):
                    self.__dataset_of_actors.add(Actor(actor.strip()))
                for genre in row["Genre"].split(","):
                    self.__dataset_of_genres.add(Genre(genre.strip()))
                index += 1
Пример #16
0
def read_movie(line):
    """
    -------------------------------------------------------
    Creates and returns a Movie object from a line of formatted string data.
    Use: movie = read_movie(line)
    -------------------------------------------------------
    Parameters:
        line - a vertical bar-delimited line of movie data in the format
          title|year|director|rating|genre codes (str)
    Returns:
        movie - a Movie object based upon the data from line (Movie)
    -------------------------------------------------------
    """

    genres = []
    line = line.split('|')
    title = line[0]
    year = int(line[1])
    director = line[2]
    rating = float(line[3])
    x = line[4].split(',')
    for i in x:
        i = int(i)
        genres.append(i)
    movie = Movie(title, year, director, rating, genres)

    return movie
Пример #17
0
    def get_awards(self, url):
        """Get the list of Movie Titles, the year of the award and the URL of the wikipedia permalink"""
        awards = []
        try:
            response = requests.get(url)
        except:
            logger.warning("Error with the URL: " + url)
    
        for table in BeautifulSoup(response.text).select('.wikitable'):
    
            #Extract Movie URL
            tr = table.select('tr')[1]
            if tr.has_key('style') and re.findall('background:#FAEB86', tr['style']):
              line = table.select('tr')[1].select('a')
              movie_url = line[0]['href']
              movie_title = line[0].text
              logger.debug(movie_title)
    
              budget = self.getBudget(self.absolutePath(movie_url))
              winning_movie = Movie(movie_title, budget, movie_url) 
              years = table.find('caption').find('big').findChildren('a', recursive=False)
              award_year = self.formatYear(years)

              if len(award_year) > 1:
                  award = Award(winning_movie, award_year[0], award_year[1])
              else:
                  award = Award(winning_movie, award_year[0])


              awards.append(award)

        return awards
Пример #18
0
def createMovie(showdate, movie_schedule):
    movie = Movie.Movie()

    movie.showdate = showdate
    movie.theater = FILM_FORUM_NAME

    # process movie url
    for link in movie_schedule.find_all('a'):
        href = link['href']
        if (href.startswith(MOVIE_URL_PREFIX)):
            movie.show_url = href

    if movie.show_url == None:
        print 'Cannot parse the movie page url on Film Forum!'
        return None

    soup = Common.getPageSoup(movie.show_url)
    if soup == None:
        return None

    parseMovieFromPage(Common.getPageSoup(movie.show_url), movie)

    for showtime in movie_schedule.find_all('span'):
        movie.addShowTime(movie.showdate, showtime.text)

    return movie
Пример #19
0
def get_movies(cursor):
    for root, dir, files in os.walk('movies'):
        for filename in files:
            if str(filename).endswith('.finished'):
                continue
            number = 0
            with open('movies/%s' % filename, 'r') as file:
                movies = json.load(file)
            try:
                for i in movies:
                    cursor.execute("select exists (select * from movies where id=%s)" % i['id'])  # 判断是否重复
                    if cursor.fetchone()[0] == 1:
                        number += 1
                        continue
                    movie = Movie(i)
                    sql = "INSERT INTO movies(TITLE,ID,DIRECTORS,SCREENWRITER,KINDS,AREA,CASTS,RATE,STAR,IMAGE,PLOT,RELEASE_DATE,RUNTIME) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" % (
                        "\"" + movie.title + "\"", movie.id, "\"" + movie.dircetors + "\"",
                        "\"" + movie.screenwriter + "\"", "\"" + movie.type + "\"", "\"" + filename[:-5] + "\"",
                        "\"" + movie.casts + "\"", movie.rate, movie.star,
                        "\"" + movie.image + "\"", "\"" + movie.plot.replace("\"", "'") + "\"",
                        "\"" + movie.date + "\"", "\"" + movie.runtime + "\"")
                    cursor.execute(sql)
                    number += 1
                    if number % 100 == 0:
                        db.commit()
                    log(filename[:-5] + '第' + str(number) + '部电影--' + movie.title + '--id:' + movie.id + '收录完成')
                db.commit()
            except Exception as message:
                db.commit()
                print(sql)
                log(filename[:-5] + str(message), 1)
                exit()

            os.rename('movies/%s' % filename, 'movies/%s' % filename + '.finished')
Пример #20
0
    def test_get_names_string(self):
        """
        Test that get_names_string returns a string that contains a list of 
        names.
        """

        # Create a movie object
        movie = Movie("R",[Name("Stanley", "", "Kubrick"),
                Name("Anthony", "", "Burgess")],
                [Name("Malcolm", "", "McDowell"), Name("Patrick", "", "Magee"),
                Name("Michael", "", "Bates")], 2, "A clockwork Orange",
                Name("Stanley", "Kubrick"),
                "Protagonist Alex DeLarge is an ultraviolent youth in "\
                "futuristic Britain. As with all luck, his eventually runs out "\
                "and he's arrested and convicted of murder and rape. While in "\
                "prison, Alex learns of an experimental program in which "\
                "convicts are programmed to detest violence. If he goes "\
                "through the program, his sentence will be reduced and he will "\
                "be back on the streets sooner than expected. But Alex's "\
                "ordeals are far from over once he hits the mean streets of "\
                "Britain that he had a hand in creating.",
                "sci-fi", "English", 1971, "US", 136,  "movie",
                ["dystopia", "violence", "alternate society"])

        # Assert expected result
        self.assertEqual(movie.get_names_string(movie.cast),
                         "Malcolm McDowell, Patrick Magee, Michael Bates")
Пример #21
0
    def test_str(self):
        """ 
        Test that str method returns a string representation of the object.
        """

        # Create a movie object
        movie = Movie("R",[Name("Stanley", "", "Kubrick"),
                Name("Anthony", "", "Burgess")],
                [Name("Malcolm", "", "McDowell"), Name("Patrick", "", "Magee"),
                Name("Michael", "", "Bates")], 2, "A clockwork Orange",
                Name("Stanley", "Kubrick"),
                "Protagonist Alex DeLarge is an ultraviolent youth in "\
                "futuristic Britain. As with all luck, his eventually runs out "\
                "and he's arrested and convicted of murder and rape. While in "\
                "prison, Alex learns of an experimental program in which "\
                "convicts are programmed to detest violence. If he goes "\
                "through the program, his sentence will be reduced and he will "\
                "be back on the streets sooner than expected. But Alex's "\
                "ordeals are far from over once he hits the mean streets of "\
                "Britain that he had a hand in creating.",
                "sci-fi", "English", 1971, "US", 136,  "movie",
                ["dystopia", "violence", "alternate society"])

        # Assert expected result of the str function
        self.assertEqual(str(movie), ("ID: 2 \nTitle: A clockwork Orange "\
                "\nCreator: Stanley  \nSummary: Protagonist Alex DeLarge is "\
                "an ultraviolent youth in futuristic Britain. \nAs with all "\
                "luck, his eventually runs out and he's arrested and "\
                "convicted... \nGenre: sci-fi \nLanguage: English "\
                "\nYear: 1971 \nCountry: US \nLength: 2h 16m \nType: movie "\
                "\nKeywords: alternate society, dystopia, violence"\
                "\nRating: R \nWriters: Stanley Kubrick, Anthony Burgess"\
                "\nCast: Malcolm McDowell, Patrick Magee, Michael Bates "))
    def read_csv_file(self):
        with open(self._file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            for row in movie_file_reader:
                # Title Add
                title = row['Title']
                release_year = int(row['Year'])
                new_movie = Movie(title, release_year)
                self.dataset_of_movies.add(new_movie)

                # Actor Add
                actors = row['Actors']
                actors_list = actors.split(",")
                for people in actors_list:
                    new_actor = Actor(people.strip())
                    if new_actor not in self.dataset_of_actors:
                        self.dataset_of_actors.add(new_actor)

                # Director Add
                director = row['Director']
                new_director = Director(director)
                if new_director not in self.dataset_of_directors:
                    self.dataset_of_directors.add(new_director)

                # Genre Add
                genre = row['Genre']
                genre_list = genre.split(",")
                for g in genre_list:
                    new_genre = Genre(g.strip())
                    if new_genre not in self.dataset_of_genres:
                        self.dataset_of_genres.add(new_genre)
Пример #23
0
def get_movies_data(movies_link):
    movies = []
    # login and create session
    with requests.session() as session:
        print('嘗試登入會員....')
        response = session.post(login_url, data=payload)
        if '歡迎您回來' in response.text:
            print('登入成功!!!! 透過電影URL開始抓取詳細資料...')
            # scrape each movie data from link
            for link in movies_link:
                movie = Movie()
                response = session.get(link)
                if response.status_code == 200:
                    print(f'開始抓取{link}頁面資料...')
                    soup = BeautifulSoup(response.text, 'html.parser')
                    movie.title = soup.find(
                        'a', id="thread_subject").text  # get movie title
                    movie.info_link = link  # create movie object

                    block_code = soup.find_all(class_='blockcode')
                    for block in block_code:
                        movie.download_link.append(
                            block.find('li').text)  # get all download link
                    movies.append(movie)
                    sleep(0.5)
                else:
                    print('連線發生錯誤')
        else:
            print('登入會員失敗...')

        # logout
        session.get(logout_url)

    return movies
Пример #24
0
 def read_csv_file(self):
     with open(self._filename, mode='r', encoding='utf-8-sig') as csvfile:
         reader = csv.DictReader(csvfile)
         index = 2
         for row in reader:
             title = row["Title"]
             release_year = int(row["Year"])
             movie1 = Movie(title, release_year)
             self._dataset_of_movies.append(movie1)
             director_name = row["Director"]
             director = Director(director_name)
             if director not in self._dataset_of_directors:
                 self._dataset_of_directors.append(director)
             actor_name_list = row["Actors"].split(",")
             index1 = 1
             for name in actor_name_list:
                 actor = Actor(name.strip())
                 if actor not in self._dataset_of_actors:
                     self._dataset_of_actors.append(actor)
                 elif actor.actor_full_name == "None":
                     print(name)
                     print(index, actor, index1)
                 index1 += 1
             genre_list = row["Genre"].split(",")
             for type in genre_list:
                 genre = Genre(type.strip())
                 if genre not in self._dataset_of_genres:
                     self._dataset_of_genres.append(genre)
             index += 1
Пример #25
0
    def fetch(self):
        result = requests.get(self.url)
        if (result.status_code != 200):
            return false

        movieList = []
        content = result.content
        soup = BeautifulSoup(content, 'html.parser')
        samples = soup.find_all(id="showtimes")  # type: ResultSet
        for s in samples:
            curMovie = Movie()
            nametag = s.find("a", "name")
            # curMovie.name =
            m = re.search(
                '\s*([ \w:;\'\"\&\%\#\@\!\+\=\/\<\>\{\}\-,\.]+)\s*\(([0-9A-Z\-]+)\)\s*',
                nametag.contents[0])
            curMovie.name = m.group(1)
            curMovie.rated = m.group(2)
            runTime = s.find_all("span", class_="smallfont")[1].contents[0]
            times = s.find("span", text="Today: ").next_sibling.next_sibling
            while self.expiredMovieTime(times) and not (times.name == 'br'):
                times = times.next_sibling
            if not (times.name == 'br'):
                curMovie.times = times.replace(',', ' ').split()
            movieList.append(curMovie)
        return movieList
Пример #26
0
def tfUserTag(userId):
    usrObj = User(userId)
    movies = di.getUserMovies(userId)
    for movieId in movies:
        movieId = movieId[0]
        mv = Movie(
            movieId,
            0)  # Here the actor movie rank is not reqd., setting this to 0
        movieTags = di.getMovieTags(movieId)
        for movieTag in movieTags:
            tagId = movieTag[0]
            timeStamp = movieTag[1]
            mv.addTag(tagId, timeStamp)
        usrObj.addMovie(mv)
    tfVector = {}
    usrObj.setUnqTags()
    unqTags = usrObj.getUnqTags()
    #print(unqTags)
    for tagId in unqTags:
        tfFactorTag = 0
        for movie in usrObj.getMovies():
            searchTags = movie.getTags()
            tfFactor = 0
            totalMovieWeight = 0
            for tag in searchTags:
                if (tag.getId() == tagId):
                    tfFactor = tfFactor + tag.getTimeWeight()
                    #print(tfFactor)
                totalMovieWeight = totalMovieWeight + 1
            if (totalMovieWeight != 0):
                tfFactorTag = tfFactorTag + tfFactor / totalMovieWeight
        tfVector[tagId] = tfFactorTag
    tfVector = utils.sortByValue(tfVector)
    return utils.normalizeVector(tfVector)
Пример #27
0
    def importCsv(self):
        """
        Import CSV data.

        The assumed format for the csv data lines is as follows:
        title,date,director,duration,genre,stars,other_stuff_can_be_ignored

        The assumed format of lists such as directors, stars, and genres is
        semicolon-separated (';'). These are converted to comma-separated
        values before adding to the tree.

        NOTE: No attempt is made to preserve information about media or series.
        """

        fileHandler = io.open(self.movieList.getFileName(), 'rt')

        # get the data and add it to the list store.
        self.movieList.movieTreeStore.clear()
        while True:
            data = fileHandler.readline()
            if not data:
                break
            dataList = data[:-1].split(',')
            movie = Movie(
                title=dataList[0],
                date=(int(dataList[1]) if dataList[1].isnumeric() else 1900),
                director=dataList[2].replace(';', ','),
                duration=(int(dataList[3]) if dataList[3].isnumeric() else 0),
                genre=dataList[4].replace(';', ','),
                stars=dataList[5].replace(';', ','),
            )
            self.movieList.movieTreeStore.append(None, movie.toList())
        fileHandler.close()
Пример #28
0
 def __init__(self, d):
     self.movie = Movie(d['movieName'], d['duration'], d['genre'],
                        d['movieid'])
     self.theater = Theater(d['theaterName'], d['distance'], d['theaterid'],
                            d['foodList'])
     self.price = d['price']
     self.showid = d['showid']
Пример #29
0
def getMovie(page):
    url = "https://yts.am/api/v2/list_movies.json?sort_by=rating&limit=20&page=1"
    response = requests.get(url=url)

    # 1. dict를 json타입으로 변경하는 방법
    # => json.dumps() - json output

    # 2. json타입을 dict으로 변경하는 방법
    # => json.loads() - json input

    html = json.loads(response.text)
    #print(html)
    #print(type(html))

    data = html['data']
    #print(data)
    #print(type(data))

    movies = data['movies']
    #print(movies)
    #print(type(movies))

    # print(movies[0]['id'])
    # print(movies[0]['title'])
    # print(movies[0]['rating'])
    # print(movies[0]['url'])
    # print(movies[0]['synopsis'])

    list = []
    for i in movies:
        m = Movie(i['rating'], i['title'], i['synopsis'],
                  i['medium_cover_image'], i['url'])
        list.append(m)

    return list
Пример #30
0
    def searchId(self, append=None):
        movieNew = Movie()

        for movieId in self.titles:
            print "Retrieving for %s..." % movieId
            movieNew = self.movieSearch.getDetails(movieId, append)
            self.movieList.setMovie(movieNew)