Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cinemagoer library problem
#6
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


Reply


Messages In This Thread
cinemagoer library problem - by lunacy90 - Sep-04-2023, 06:19 PM
RE: cinemagoer library problem - by menator01 - Sep-04-2023, 06:28 PM
RE: cinemagoer library problem - by deanhystad - Sep-04-2023, 06:45 PM
RE: cinemagoer library problem - by lunacy90 - Sep-04-2023, 07:55 PM
RE: cinemagoer library problem - by deanhystad - Sep-04-2023, 08:15 PM
RE: cinemagoer library problem - by menator01 - Sep-05-2023, 12:59 AM
RE: cinemagoer library problem - by deanhystad - Sep-05-2023, 01:41 AM
RE: cinemagoer library problem - by menator01 - Sep-05-2023, 03:24 AM
RE: cinemagoer library problem - by lunacy90 - Sep-05-2023, 10:12 AM
RE: cinemagoer library problem - by lunacy90 - Sep-05-2023, 10:58 AM
RE: cinemagoer library problem - by menator01 - Sep-07-2023, 04:47 PM
RE: cinemagoer library problem - by lunacy90 - Sep-05-2023, 11:58 AM
RE: cinemagoer library problem - by deanhystad - Sep-05-2023, 12:24 PM
RE: cinemagoer library problem - by lunacy90 - Sep-05-2023, 01:30 PM
RE: cinemagoer library problem - by menator01 - Sep-05-2023, 09:30 PM
RE: cinemagoer library problem - by deanhystad - Sep-05-2023, 10:21 PM
RE: cinemagoer library problem - by menator01 - Sep-05-2023, 11:50 PM
RE: cinemagoer library problem - by menator01 - Sep-06-2023, 08:06 AM
RE: cinemagoer library problem - by lunacy90 - Sep-08-2023, 03:16 PM
RE: cinemagoer library problem - by deanhystad - Sep-07-2023, 06:37 PM
RE: cinemagoer library problem - by menator01 - Sep-07-2023, 06:56 PM
RE: cinemagoer library problem - by menator01 - Sep-08-2023, 04:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with importing python-telegram library into the project gandonio 1 1,618 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  Problem with using Crypto library reks2004 2 2,452 Mar-27-2020, 05:38 AM
Last Post: buran
  Problem installing library thunderspeed 2 2,358 Mar-22-2020, 11:04 PM
Last Post: thunderspeed
  Problem importing resource library ChrisM 8 4,009 Oct-23-2019, 01:40 PM
Last Post: ChrisM
  Problem Using Python Library abir99 8 5,438 Nov-21-2017, 03:12 PM
Last Post: sparkz_alot
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,863 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020