from omdbapi.movie_search import GetMovie
def get_movie_data(api_key, titles):movie_data = {}movie_api = GetMovie(api_key=api_key)
for title in titles: # Attempt to fetch the movie information try: result = movie_api.get_movie(title=title) # Check if movie details were found and the title matches the queried title if result and result.get('Response', 'False') == 'True' and result.get('Title') == title: movie_data[result.get('Title')] = result except GetMovieException as e: # Handle "Movie not found" exception print(f"Movie not found: {title}") continue except Exception as e: # Handle other exceptions print(f"Error querying title {title}: {e}") continuereturn movie_dataapi_key = 'api-key'
titles = [x for x in movie_data['title'].head(10)] # Adjust based on your actual data
movies_info = get_movie_data(api_key, titles)
print(movies_info)
Having issues iterating over a list of movies to obtain the information using the omdb API. Has anyone used this API before that can point me in the right direction?
I was expecting to get a dictionary of titles and movie information. However, when I iterate over the list of movies, I get the same information for all movies.