cinemagoer library problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: cinemagoer library problem (/thread-40671.html) |
cinemagoer library problem - lunacy90 - Sep-04-2023 I am trying to make an application that in part prints out the last 10 films released based on actor which means i want to exclude announced films if they haven/t been released yet def get_data_actor_name(id): global movie_name,cg search = cg.get_person(id) filmography=cg.get_person_filmography(id) last_ten_films=filmography['data']['filmography']['actor'] for movie in last_ten_films: if bool(movie['year']): movie_name.append(movie['title'], movie['year']) messagebox.showinfo(title=f"{search}'s latest film information", message=f"{movie_name}") movie_name.clear()the code above returns a KeyError (year) as you can see below
RE: cinemagoer library problem - menator01 - Sep-04-2023 Where is the data coming from? Is it coming from a database? I don't really understand why using the global. Need a little more information please. RE: cinemagoer library problem - deanhystad - Sep-04-2023 The data comes from Cinemagoer, an IMDB scraper package. Lunacy probably should have posted this question in the original thread instead of starting a new one and losing all the context. https://python-forum.io/thread-40667.html 'year' must not be a key in movie. You should print out all the keys in movie to find out what they are. There is no need for the global declaration. You only need to declare a variable name as global if you assign a value to the name. In get_data_actor_name() there are no assignments made to cg, and movie_name is obviously a local variable because it is cleared at the end of the function. Posted code should be runable. This means including imports and any setup code. RE: cinemagoer library problem - lunacy90 - Sep-04-2023 (Sep-04-2023, 06:45 PM)deanhystad Wrote: The data comes from Cinemagoer, an IMDB scraper package. Lunacy probably should have posted this question in the original thread instead of starting a new one and losing all the context. and how can i print all of the keys in "movie"? cause when i tried printing i can only see the name of the feature and no other information RE: cinemagoer library problem - deanhystad - Sep-04-2023 Maybe that is all there is. Or maybe there is the name of the move and an ID, and you need to look up the move to get the movie information. I always felt it was called web scraping because that is what you have to do. Scrape away layer after layer of information to finally find what you are looking for. RE: cinemagoer library problem - menator01 - Sep-05-2023 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
RE: cinemagoer library problem - deanhystad - Sep-05-2023 This does not agree with IMDB. Tough being cast in a move filmed before you are born. Missing the Kung Fu Pandas movies, one of the Lara Croft movies. Maybe get_person_biography is not the way to get this info? RE: cinemagoer library problem - menator01 - Sep-05-2023 Could use filmography but, returns a lot of stuff that I don't know if it even involves jolie I think it's the database. I used harrison ford and got movies that he was not in. The years were 1962 and 1967. Samething with Jason Statham. The database has input year errors. Here is the ouput for Statham
RE: cinemagoer library problem - lunacy90 - Sep-05-2023 (Sep-05-2023, 03:24 AM)menator01 Wrote: Could use filmography but, returns a lot of stuff that I don't know if it even involves joliethanks a lot for your help guys. Ill add your usernames in my github page as collaborators RE: cinemagoer library problem - lunacy90 - Sep-05-2023 (Sep-05-2023, 03:24 AM)menator01 Wrote: Could use filmography but, returns a lot of stuff that I don't know if it even involves jolieone more question, hopefully it will be the last. I try to search via company name with the search_company function. I then pass the definitive name to the get_company function which requests an ID for the parameter. How can i get the ID of the company straight from the search_company function? I tried printing it but i only get the name of the company printed. ive tried a generic movie_id or movieId or id option but i get a KeyError my code follows this is the function that gets all the results based by the name to find the correct company name which the user is looking for. for i in range(len(search)): if messagebox.askokcancel(title=f"Company Name",message=f"Is {search[i]} the company you are looking for?"): id=search[i] print(id) get_data_company(id)the above function loads another function that will follow below def get_data_company(id): print(id) company=cg.get_company(str(id)) print(company["name"])the elements i have yet to add to this function are the name retrievals from the films and i want to create a new list of the 10 most recent films made by the company that the user is looking for EDIT: i set up the search by actor name function. It works ok but there is a small problem. I splice the actors filmography to get the first 10 films sorted by release year but it doesnt actually contain the newest ones. For example i searched for Keanu Reeves and his newest film in the list was Matrix Revolutions not John Wick Chapter 4 as it is in real life. My code follows below def get_data_actor_name(id): data=[] global cg search = cg.search_person(id) person=search[0] filmography=cg.get_person_biography(id) for film in filmography["titlesRefs"].values(): try: year=film["year"] except KeyError: year="No date available" data.append((film["title"],year)) data.sort(key=lambda a: a[1]) data.reverse() headers=["Movie","Year"] filmography=data[:10] messagebox.showinfo(title=f"{search}'s latest film information", message=f"{headers}\n" f"{filmography[0]}\n" f"{filmography[1]}\n" f"{filmography[2]}\n" f"{filmography[3]}\n" f"{filmography[4]}\n" f"{filmography[5]}\n" f"{filmography[6]}\n" f"{filmography[7]}\n" f"{filmography[8]}\n" f"{filmography[9]}\n" f"") |