One way to do it
from imdb import Cinemagoer from pandas import DataFrame as df from tabulate import tabulate class Model: def __init__(self): self.ia = Cinemagoer() def search_person(self, name): data = [] people = self.ia.search_person(name.strip()) person = people[0] id = person.personID films = self.ia.get_person_biography(id) for film in films['titlesRefs'].values(): try: year = film['year'] except KeyError: year = 'No date available' data.append((film['title'], year, film.movieID)) return data def search_movie(self, title): data = [] movies = self.ia.search_movie(title.strip()) for movie in movies: data.append((movie['title'], movie['year'], movie.movieID)) return data m = Model() data = m.search_person('angelina jolie') data.sort(key=lambda a: a[1]) headers = ['Movie', 'Year', 'Movie ID'] print('All Movies') print(tabulate(df(data), showindex=False, headers=headers)) print() # Search < date alist = [] for movie, year, id in data: if isinstance(year, int) and year <= 1998: alist.append((movie, year, id)) print('Movies less than or equal to 1998') print(tabulate(df(alist), showindex=False, headers=headers)) print() data.reverse() print('Last five movies') print(tabulate(df(data[:5]), showindex=False, headers=headers))output
Output:All Movies
Movie Year Movie ID
------------------------------- ------ ----------
One Flew Over the Cuckoo's Nest 1975 0073486
Hackers 1995 0113243
Foxfire 1996 0116353
True Women 1997 0118499
George Wallace 1997 0119189
Gia 1998 0123865
Girl, Interrupted 1999 0172493
The Bone Collector 1999 0145681
Pushing Tin 1999 0120797
The Matrix 1999 0133093
Lara Croft: Tomb Raider 2001 0146316
Beyond Borders 2003 0294357
Mr. & Mrs. Smith 2005 0356910
Wanted 2008 0493464
Salt 2010 0944835
Maleficent 2014 1587310
Unbroken 2014 1809398
By the Sea 2015 3707106
Eternals 2021 9032400
Movies less than or equal to 1998
Movie Year Movie ID
------------------------------- ------ ----------
One Flew Over the Cuckoo's Nest 1975 0073486
Hackers 1995 0113243
Foxfire 1996 0116353
True Women 1997 0118499
George Wallace 1997 0119189
Gia 1998 0123865
Last five movies
Movie Year Movie ID
---------- ------ ----------
Eternals 2021 9032400
By the Sea 2015 3707106
Unbroken 2014 1809398
Maleficent 2014 1587310
Salt 2010 0944835
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags