app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from imdb import IMDb import json # Create an instance of the IMDb class ia = IMDb() # Search for the movie movie_title = "Jurassic Park" movies = ia.search_movie(movie_title) if movies: movie = ia.get_movie(movies[0].movieID) # Extract details data = { 'Title': movie.get('title'), 'Year': movie.get('year'), 'Genre': movie.get('genres', []), 'Director': [d['name'] for d in movie.get('directors', [])], 'Rating': movie.get('rating'), 'Plot': movie.get('plot outline'), 'Cast': [actor['name'] for actor in movie.get('cast', [])[:10]] # Top 10 cast members } # Save to JSON with open('movie_info.json', 'w', encoding='utf-8') as f: json.dump(data, f, indent=4, ensure_ascii=False) print("Movie info with cast saved to movie_info.json") else: print("Movie not found.") |