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
评论列表
文章目录