helpers.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Silver-Screen 作者: bfbachmann 项目源码 文件源码
def search(self, title):
        """
        :params title: a string holding the title of the movie
        :return movie: if at least one movie with a similar title is found, this is a Movie object
                      created from the most relevant result returned by OMDb, otherwise it is empty list
        """
        ## Search for all movies with similar titles
        try:
            matching_movies = omdb.search_movie(title)
        except:
            raise ConnectionError

        ## Return most relevant movie
        highestIMDB = 0

        if matching_movies:
            movie = matching_movies.pop(0)
            print("MOVIE: " + movie.title)

            try:
                movieObj = Movie.objects.get(imdbID=movie.imdb_id)
            except Movie.DoesNotExist:
                movieObj = None

            if not movieObj:
                response = omdb.request(i=movie.imdb_id, tomatoes=True, type='movie').json()
                movieObj = Movie().fillWithJsonObject(response)
                if not movieObj:
                    return None

            self.known_omdb_titles.append(movieObj.Title)
            return movieObj
        else:
            return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号