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 parseAndSave(s):
  for l in s.find (id="data_list").findAll("tr"):
    try:
      tagALinkToDetail = l.find(has_link_to_show_php)
      if tagALinkToDetail: 
        fullText=tagALinkToDetail.text.strip()
        logger.info("Searching info in douban with keyword: %s" % fullText)
        
        m = Movie(fullText)
        m.source_link = tagALinkToDetail['href']
        m.numberOfSeeds=int(tagALinkToDetail.parent.parent.find(class_='bts_1').text)
        m.source_link=str(tagALinkToDetail["href"])
        bucket = Bucket('couchbase://localhost/default')
        v=json.dumps(m.__dict__)
        bucket.upsert(fullText,v)
      else:
        logger.debug("skip a line in mp4ba resource page, most likely because it is an ads")
    except AttributeError as ae:
      logger.error (ae)
      logger.error ("Error! Skipped when trying to parse: %s" % l)
      exit 
    except Exception as e:
      logger.error (e)
      logger.error ("Error! Skipped when trying to parse: %s" % l)
      exit
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)
Пример #4
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")
Пример #5
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
Пример #6
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)
Пример #7
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()
Пример #8
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
Пример #9
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()
Пример #10
0
def parseMoviesAndRatings():
    inputFile = open("../dataset/movie_rating.txt")    
    lineString = inputFile.readline()
    movieRatingVector = np.zeros(0)
    global missing_count
        
    while(lineString):
        (movie_title,movie_year) = Movie.separateTitleAndYear(lineString.split("\t\t")[0].strip())
        movie_rating = float(lineString.split("\t\t")[1].strip())        
        
        if(not movie_title in Movie.hashByTitle):
            movie = Movie(movie_title,rating=movie_rating)
            missing_count = missing_count + 1
        else:    
            movie = Movie.hashByTitle[movie_title]
        
        movie.rating = movie_rating
        
        movieRatingVector = np.append(movieRatingVector,movie_rating)
        
        lineString = inputFile.readline()     
                
        if(movie.id%100000 == 0):
            print movie      
    
    arrayToSave = np.asarray(movieRatingVector)
    np.savetxt("./movie_rating_vector.csv", arrayToSave, delimiter=",")
Пример #11
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
Пример #12
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)
Пример #14
0
def main():
    input_list = ['the-matrix', 'hellboy']
    review_dict = {}
    for title in input_list:
        movie = Movie(title, Soup())
        movie.set_all_reviews()
        review_dict[title] = movie
        print(review_dict[title].get_all_reviews())
Пример #15
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
Пример #16
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"
Пример #17
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
Пример #18
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>"
     )
Пример #19
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"
     )
Пример #20
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
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)
Пример #22
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
Пример #23
0
def tfMovTag(movieId):
    mv = Movie(movieId,
               0)  # Here the actor movie rank is not reqd., setting this to 0
    movieTags = di.getMovieTags(movieId)
    #print("tags are")
    #print(movieTags)
    for movieTag in movieTags:
        tagId = movieTag[0]
        timeStamp = movieTag[1]
        mv.addTag(tagId, timeStamp)
    tfArray = utils.getGenreMovieTags(mv)
    return tfArray


#print(tfMovTag('3854'))
Пример #24
0
    def _buildMovieObj(self, movieInfo):
        movie = Movie(movieInfo["name"])
        movie.movieYear = movieInfo["year"]
        movie.pictureLink = movieInfo["picture"]
        movie.magnetLink = movieInfo["magnet"]
        movie.quality = movieInfo["quality"]
        movie.seeders = movieInfo["seeders"]
        movie.imdb = movieInfo["imdb"]
        movie.ranking = movieInfo["rating"]
        movie.summary = movieInfo["summary"]

        return movie
Пример #25
0
def parseActorsAndMovies():    
    Actor.unpickleActors()
    if(not Actor.total):
        print "Reading all actor data from dataset..."
        inputFile = open("../dataset/actor_movies.txt")
        lineString = inputFile.readline()
        
        while(lineString):
            actor_name = "" 
            parsedLineArray = lineString.split("\t\t")
            
            for i in range(0,len(parsedLineArray)):
                if(i == 0):
                    actor_name = parsedLineArray[0].strip()
                    actor = Actor(actor_name)            
                else:            
                    if(parsedLineArray[i].strip() != ""):
                        (movieTitle,movieYear) = Movie.separateTitleAndYear(parsedLineArray[i].strip())             
                        movieActedIn = Movie.hashByTitle[movieTitle]                
                        #Set actor's movie list
                        actor.movieList.append(movieActedIn)
                        #Update actor's movieVector for current movie
                        actor.moviesVector[0][movieActedIn.id] = 1        
                        #Append current movie's actor list with current actor
                        movieActedIn.actors.append(actor)
            
            lineString = inputFile.readline()
            print actor
            #Append actor's moviesVector to the actorMovieMatrix
            if(Actor.total == 1):
                Actor.actorMovieAdjacencyMatrix = np.append(np.zeros((0,Movie.total)),actor.moviesVector,axis=0)
            else:
                Actor.actorMovieAdjacencyMatrix = np.append(Actor.actorMovieAdjacencyMatrix,actor.moviesVector,axis=0)
        Actor.pickleActors()
Пример #26
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
Пример #27
0
  def toxml(self, stylesheet="proviola.xsl"):
    frame_doc = Movie.toxml(self, stylesheet)    
    # Entitites taken from Symbols.v in the SF notes.
    entity_map = {
      "nbsp":   "&#160;",
      "mdash":  "&#8212;",
      "dArr":   "&#8659;",
      "rArr":   "&#8658;",
      "rarr":   "&#8594;",
      "larr":   "&#8592;",
      "harr":   "&#8596;",
      "forall": "&#8704;",
      "exist":  "&#8707;",
      "exists": "&#8707;",
      "and":    "&#8743;",
      "or":     "&#8744;",
      "Gamma":  "&#915;",
    }

    entities = "\n".join(
                ['<!ENTITY %s "%s">'%(key, entity_map[key]) 
                 for key in entity_map])
    frame_doc.insert(1, Declaration("DOCTYPE movie [" + entities + "]"))
    scene_tree = Tag(frame_doc, "scenes")
    frame_doc.movie.append(scene_tree)
      
    for scene in self._scenes:
      scene_tree.append(scene.toxml(frame_doc))      
        
    return frame_doc
Пример #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 toxml(self, stylesheet="proviola.xsl"):
        frame_doc = Movie.toxml(self, stylesheet)
        # Entitites taken from Symbols.v in the SF notes.
        entity_map = {
            "nbsp": "&#160;",
            "mdash": "&#8212;",
            "dArr": "&#8659;",
            "rArr": "&#8658;",
            "rarr": "&#8594;",
            "larr": "&#8592;",
            "harr": "&#8596;",
            "forall": "&#8704;",
            "exist": "&#8707;",
            "exists": "&#8707;",
            "and": "&#8743;",
            "or": "&#8744;",
            "Gamma": "&#915;",
            "quot": "&#34;",
            "acute": "&#180;",
        }

        entities = "\n".join([
            '<!ENTITY %s "%s">' % (key, entity_map[key]) for key in entity_map
        ])
        frame_doc.insert(1, Declaration("DOCTYPE movie [" + entities + "]"))
        scene_tree = Tag(frame_doc, "scenes")
        frame_doc.movie.append(scene_tree)

        for scene in self._scenes:
            scene_tree.append(scene.toxml(frame_doc))

        return frame_doc
Пример #31
0
    def extractMovieTreeAsList(self, treeIter):
        """
        Extract the movie data from the movieTreeStore in the form of a list.

        Recursively construct a list of the movies and series in the rows and
        child rows of the store.
        The base treeIter should point to the tree root, i.e.,
        movieTreeStore.get_iter_first().
        The list is sorted by title before returning.
        """

        list = []
        while treeIter:
            if self.movieList.movieTreeStore[treeIter][-1]:
                seriesList = []
                if self.movieList.movieTreeStore.iter_has_child(treeIter):
                    childIter = \
                        self.movieList.movieTreeStore.iter_children(treeIter)
                    seriesList.extend(self.extractMovieTreeAsList(childIter))
                    list.append(
    MovieSeries.fromList(self.movieList.movieTreeStore[treeIter], seriesList))
            else:
                list.append(
    Movie.fromList(self.movieList.movieTreeStore[treeIter]))

            treeIter = self.movieList.movieTreeStore.iter_next(treeIter)

        return sorted(list, key=lambda item:item.title)
Пример #32
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
Пример #33
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
Пример #34
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
Пример #35
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
Пример #36
0
    def on_copyAction_activate(self, widget):
        """
        Handler for the movie copy action. Add a duplicate movie entity to the
        list.
        """

        # the status bar context
        contextId = self.statusbar.get_context_id(COPY)

        # select the movie/series to change
        treeIndex, movieEntity = self.getMovieOrSeriesFromSelection(contextId,
                                                                    COPY)
        if not movieEntity:
            return
        seriesIndex = None
        copiedMovieEntity = copiedSeriesIndex = None

        if isinstance(movieEntity, MovieSeries):
            copiedMovieEntity = MovieSeries.fromList(movieEntity.toList(), [])
        else:
            copiedSeriesIndex = self.findParentMovieSeries(treeIndex)
            copiedMovieEntity = Movie.fromList(movieEntity.toList())

        # update the model and display
        self.addMovieEntity(contextId, COPY, Gtk.ResponseType.OK,
                            None,
                            None, None,
                            copiedMovieEntity, copiedSeriesIndex)
Пример #37
0
    def extractMovieTreeAsList(self, treeIter):
        """
        Extract the movie data from the movieTreeStore in the form of a list.

        Recursively construct a list of the movies and series in the rows and
        child rows of the store.
        The base treeIter should point to the tree root, i.e.,
        movieTreeStore.get_iter_first().
        The list is sorted by title before returning.
        """

        list = []
        while treeIter:
            if self.movieList.movieTreeStore[treeIter][-1]:
                seriesList = []
                if self.movieList.movieTreeStore.iter_has_child(treeIter):
                    childIter = \
                        self.movieList.movieTreeStore.iter_children(treeIter)
                    seriesList.extend(self.extractMovieTreeAsList(childIter))
                    list.append(
                        MovieSeries.fromList(
                            self.movieList.movieTreeStore[treeIter],
                            seriesList))
            else:
                list.append(
                    Movie.fromList(self.movieList.movieTreeStore[treeIter]))

            treeIter = self.movieList.movieTreeStore.iter_next(treeIter)

        return sorted(list, key=lambda item: item.title)
Пример #38
0
 def make_frames(self, service_uri = "http://localhost:8080/xmlrpc/xmlrpc",
                       filename = "",
                       *args):
   document = Movie()
   isabelle_session = Isabelle_Session(service_uri, filename)
   contents = self.script
   isabelle_session.add(contents)
   #TODO: Poll for change (or comet-push on change?)
   time.sleep(10)
   tree = parseString("<document>" + isabelle_session.document_as_xml() +
                      "</document>")
   
   for node in tree.documentElement.childNodes:
     if node.nodeType != Node.TEXT_NODE and node.tagName == "state":
       document.addFrame(self.state_to_frame(node))
   return document
Пример #39
0
def parseMoviesAndGenre():
    Movie.unpickleMovies()
    if(not Movie.total):
        inputFile = open("../dataset/movie_genre.txt")    
        lineString = inputFile.readline()
        
        while(lineString):
            movie_title = lineString.split("\t\t")[0].strip()
            movie_genre = lineString.split("\t\t")[1].strip()
            
            movie = Movie(movie_title,genre=movie_genre)
            
            Movie.list.append(movie)
            
            lineString = inputFile.readline()
            
            if(movie.id%100000 == 0):
                print movie   
        Movie.pickleMovies()
Пример #40
0
    def reParentChildren(self, seriesIter, newSeriesIter):
        """
        Take the children of a series to be deleted and re-parent them to the
        root, or another named series.
        """

        childIter = self.movieTreeStore.iter_children(seriesIter)
        while childIter:
            movie = Movie.fromList(self.movieTreeStore[childIter])
            self.movieTreeStore.remove(childIter)
            self.movieListIO.appendMovieToStore(movie, newSeriesIter)
            childIter = self.movieTreeStore.iter_children(seriesIter)
Пример #41
0
def addMoviesToDatabase(session, movies):
    nAdded = 0
    for movie in movies:
        movieImdbId = movie[0]
        movieTitle = movie[1]
        movieYear = movie[2]

        # Check if the movie is already in the database
        q = session.query(Movie).filter(Movie.imdbId == movieImdbId)
        if len(q.all()) == 0:
            print "Adding "+movieImdbId+": "+movieTitle+" ("+movieYear+") to database.."
            # If not add it to the database
            newMovie = Movie(movieTitle, movieYear)
            newMovie.imdbId = movieImdbId
            newMovie.last_searched = 0
            newMovie.downloaded = 0
            session.add(newMovie)
            nAdded += 1

    session.commit()
    session.close()
    return nAdded
Пример #42
0
  def make_frames(self, prover = None):
    """ Splits the file stored in self.script into seperate commands,
        and pairs these commands to their responses as provided by prover.

        Arguments:
        - prover: The prover to send commands to.
    """

    document = Movie()
    command = self.getCommand()

    while command != None and len(command) != 0:
      if self.isComment(command):
        response = None
      else:
        response = prover.send(command)

      id = 0
      document.addFrame(Frame(id, command, response))
      command = self.getCommand()

    return document
Пример #43
0
def get_movie(root, path):
    def get_movie_files(movie_path):
        return [movie_file for movie_file in os.listdir(movie_path)
                if os.path.isfile(os.path.join(movie_path, movie_file))
                and (os.path.splitext(movie_file)[1] in utils.get_movie_extensions())]

    if not os.path.exists(os.path.join(root, path)):
        raise OSError('Path do not exist')

    movie = Movie()
    movie.path = path

    rx = regex.get_movie(movie.path)
    movie.search_year = rx['year']
    movie.imdb = rx['imdbID']
    movie.search_title = rx['title']
    movie.search_alternative_title = utils.replace(rx['title'])
    movie.path = os.path.join(root, movie.path)

    files = get_movie_files(movie.path)
    if len(files) < 1:
        return movie

    # todo: this *should* not longer be needed,
    if 'new.mkv' in files and len(files) > 1:
        os.remove(os.path.join(movie.path, 'new.mkv'))
        files = get_movie_files(movie.path)

    # todo: implement multi cd support
    if len(files) == 1:
        movie.files = [files[0]]

    if len(files) > 1:
        # get only files that are tagged as CD
        for _file in [f for f in files if regex.get_cd(f) == '']:
            files.remove(_file)

        movie.files = files

    return movie
Пример #44
0
    def getMovieOrSeriesFromSelection(self, contextId, context):
        """
        Obtain a movie or series from the currently-selected treeView row.
        """

        # get the current movie selection
        parentModel, parentIter = self.movieTreeSelection.get_selected()

        treeModel = self.movieTreeStore
        treeIndex = getChildModelSelection(parentModel, parentIter)
        if treeIndex is None:
            self.displaySelectMovieErrorMessage(contextId, context)
            return None, None
        if treeModel[treeIndex][-1]:
            childIter = treeModel.iter_children(treeIndex)
            seriesList = self.movieListIO.extractMovieTreeAsList(childIter)
            return treeIndex, MovieSeries.fromList(treeModel[treeIndex],
                                                   seriesList)
        else:
            return treeIndex, Movie.fromList(treeModel[treeIndex])
Пример #45
0
 def getDetails(self, movieId, append = None):
     apiArgs = {'api_key' : self.api_key, 'append_to_response' : append}
     query = API_URL + self.api_media + movieId + "?" + urlencode(apiArgs)
     apiRequest = Request(query, headers=HEADERS)
     result = urlopen(apiRequest).read()
     data = json.loads(result)
     
     genres = self.getGenres(data)
     cast = self.getCast(data)
     
     tempMovie = Movie()
     tempMovie.setId(movieId)
     tempMovie.setTitle(data[self.title])
     tempMovie.setReleaseDate(data[self.date])
     tempMovie.setGenre(genres)
     tempMovie.setCast(cast)
     tempMovie.setPosterPath(data['poster_path'])
     
     return tempMovie
Пример #46
0
  def __init__(self):
    """ Initialize an empty Movie. """
    Movie.__init__(self)

    self._title = ""
    self._scenes = []
Пример #47
0
 def setUp(self):
   """ Setup: just construct a movie """
   self.movie = Movie()
Пример #48
0
class Test_Movie(unittest.TestCase):
  """ A set of test cases for movies. """

  def setUp(self):
    """ Setup: just construct a movie """
    self.movie = Movie()


  def test_AddFrame(self):
    """ Addition of a frame in order should yield correct IDs """
    frame1 = Frame(command = "command1", response = "response1")
    self.movie.addFrame(frame1)

    frame2 = Frame(command = "command2", response = "response2")
    self.movie.addFrame(frame2)

    frame3 = Frame(command = "command3", response = "response3")
    self.movie.addFrame(frame3)

    self.assertEquals(self.movie.getLength(), 3)
    self.assertEquals(frame1.getId(), 0)
    self.assertEquals(frame2.getId(), 1)
    self.assertEquals(frame3.getId(), 2)

  def _storeOpenAndCompareMovie(self):
    self.movie.toFile(TESTFILM_PATH)
    importMov = Movie()
    importMov.openFile(TESTFILM_PATH)

    self.assertEquals(str(self.movie.toxml()), str(importMov.toxml()))

  def testToFromXML(self):
    """ Writing and loading an empty Movie should give the same document """
    self._storeOpenAndCompareMovie()

  def testAddToFromXML(self):
    self.movie.addFrame(Frame(command="cmd", response="resp"))
    self._storeOpenAndCompareMovie()

  def testSemiEmptyExport(self):
    self.movie.addFrame(Frame(command="cmd", response=""))
    self._storeOpenAndCompareMovie()

  def testEmptyExport(self):
    self.movie.addFrame(Frame(command="cmd"))
    self._storeOpenAndCompareMovie()

  def testIds(self):
    """ Test if getFrameById works """
    f1 = Frame(command = "cmd1", response = "rsp1")
    f2 = Frame(command = "cmd2", response = "rsp2")
    self.movie.addFrame(f1)
    self.movie.addFrame(f2)

    f1ById = self.movie.getFrameById(f1.getId())

    self.assertEqual(f1, f1ById)
Пример #49
0
  def _storeOpenAndCompareMovie(self):
    self.movie.toFile(TESTFILM_PATH)
    importMov = Movie()
    importMov.openFile(TESTFILM_PATH)

    self.assertEquals(str(self.movie.toxml()), str(importMov.toxml()))
Пример #50
0
 def getMovie(self, code, profile = DEFAULT_PROFILE):
   retval = Movie(code = code)
   retval.getInfo(profile)
   return retval
Пример #51
0
    d = json.loads(urllib2.urlopen(url).read())
    return self.SearchResults(d["feed"])

  def getMovie(self, code, profile = DEFAULT_PROFILE):
    retval = Movie(code = code)
    retval.getInfo(profile)
    return retval

  def getPerson(self, code, profile = DEFAULT_PROFILE):
    retval = Person(code = code)
    retval.getInfo(profile)
    return retval

  def reviewList(self, movie_code):
    d = json.loads(urllib.urlopen("http://api.allocine.fr/rest/v3/reviewlist?partner=%s&format=json&code=%s" % (PARTNER_CODE, movie_code)).read())
    return [Review(**i) for i in d["feed"]["review"]]

if __name__ == "__main__":
  p = Allocine().search("robert de niro").persons[0]
  p.getFilmography()
  for m in p.filmography:
    print("%s played in %s" % (p, m.movie))
  m = Movie(code=  32070)
  m.getInfo(profile = "large")

  print("searching 'le parrain'")
  results = Allocine().search("the godfather")
  movie = results.movies[0]
  print("first result is %s" % movie)
  movie.getInfo()
  print("synopsis of %s : %s" % (movie, movie.synopsisShort))
Пример #52
0
    def getString(self):
        movieString = ""
        for movieId in self.movieList:
            movieString += movieId.getString(";") + "\n"

        return movieString


if __name__ == "__main__":
    tempMovieList = MovieList()

    for i in xrange(10):
        tempMovie = Movie(
            str(i),
            "Fight Club",
            "1999-10-15",
            ["Action", "Drama", "Thriller"],
            ["Edward Norton", "Brad Pitt"],
            "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg",
        )

        tempMovieList.setMovie(tempMovie)

    print tempMovieList.getString()

    for j in xrange(10):
        tempMovie = tempMovieList.getMovie(str(j))

        if tempMovie is not None:
            print tempMovie.getString(";")

    print ""
Пример #53
0
def save_movie_info_to_mongo(title, rt_id=None, save_similar_movies=False,
        overwrite=False):
    AWS_ACCESS_KEY = settings.Config.AWS_ACCESS_KEY
    AWS_SECRET_KEY = settings.Config.AWS_SECRET_KEY
    AWS_AFFILIATE_KEY = settings.Config.AWS_AFFILIATE_KEY
    ROTTEN_TOMATOES_API_KEY = settings.Config.ROTTEN_TOMATOES_API_KEY
    TMDB_API_KEY = settings.Config.TMDB_API_KEY

    if not overwrite and Movie.objects(_title=title).first() is not None:
        print "{title}found in db".format(title=title)
        return

    print "searching {title}".format(title=title)
    movie = MovieInfo(title, ROTTEN_TOMATOES_API_KEY, TMDB_API_KEY,
                AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_AFFILIATE_KEY,
                rt_id=rt_id)
    # save the movie's information to the database:
    # raw movie data
    cast = movie.cast
    critics_score = movie.critics_score
    director = movie.director 
    genres = movie.genres
    imdb_id = movie.imdb_id
    poster = movie.poster
    release_date = movie.release_date
    reviews = movie.critic_reviews
    runtime = movie.runtime
    similar_movies = movie.similar_movies
    synopsis = movie.synopsis
    title = movie.title
    trailers = movie.trailers
    amazon_purchase_links = movie.get_amazon_purchase_links(cast[0], runtime)
    
    # formatting some raw data into more complex sets of data
    actors = convert_cast_json_to_obj(cast)
    amazon_purchase_links = convert_amazon_purchase_link_json_to_obj(
        amazon_purchase_links)
    formatted_director = format_string(movie.director)
    formatted_title = format_string(title)
    reviews = convert_review_json_to_obj(reviews)
    metadata = convert_to_metadata(imdb_id, runtime)
    thumbnail = create_thumbnail(formatted_title, poster, verbose=True)
    similar_movies_imdb_ids = convert_similar_movies_to_imdb_ids(
        similar_movies)
    
    kargs ={"_director": director,
            "_formatted_director": formatted_director,
            "_title": title,
            "_formatted_title": formatted_title, 
            "_synopsis": synopsis,
            "_critics_score": critics_score,
            "_release_date": release_date,
            "_poster": poster,
            "_thumbnail": thumbnail,
            "_cast": actors, 
            "_genres": genres,
            "_metadata": metadata, 
            "_reviews": reviews,
            "_similar_movies": similar_movies_imdb_ids,
            "_trailers": trailers,
            "_purchase_links": amazon_purchase_links}

    if not overwrite:
        print "saving {title}".format(title=title)
        new_movie = Movie(**kargs)
        new_movie.save()
        index_movie(new_movie, verbose=True)
        update_actors(actors, new_movie, verbose=True)
    else:
        print "updating {title}".format(title=title)
        Movie.objects(_formatted_title=formatted_title).first().save(**kargs)

    # save this movie's similar movies to mongo
    if save_similar_movies:
        for similar_movie in similar_movies:
            title = similar_movie['title']
            rt_id = similar_movie['id']
            save_movie_info_to_mongo.delay(title, rt_id=rt_id, 
                save_similar_movies=True)
            print "queuing up {title}".format(title=title)