imdby package 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: imdby package problem (/thread-40667.html) |
imdby package problem - lunacy90 - Sep-04-2023 I am trying to build an app that connects on imdb module and will be able to access diferent kinds of information about the film in question from imdby.imdb import imdb details=imdb("tt4154796") print(details)My problem is whenever i try to run it i get an IndexError code. Can someone help me understand whats going wrong here? RE: imdby package problem - deanhystad - Sep-04-2023 Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error? My guess would be that tt4154796 is not a valid id. I did type this in as a search on imdb.com and it pulled up Avengers: End Game, so maybe the problem is something else. Hard to say without any information about the error. Why are you using this package instead of something like Cinemagoer (used to be imdbPy)? RE: imdby package problem - lunacy90 - Sep-04-2023 (Sep-04-2023, 01:54 PM)deanhystad Wrote: Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error? ok so basically i updated my code a bit. I first look for a movie based on title. I then confirm that is the movie the user is looking for. After that i try to receive information about the movie based on the movie ID. However i still have the same problem. Basically i want to be able to get movie data from the movie id variable and use that to print out data like director(s),actor(s) etc. My code is: import imdb as im from tkinter import * from tkinter import simpledialog,messagebox from imdby.imdb import imdb def get_data(movie_id): details=imdb(movie_id) print(details) messagebox.showinfo(title="Movie Information",message=f"{details}") def search_for_film(name): cg = im.Cinemagoer() search = cg.search_movie(name) for i in range(len(search)): if messagebox.askokcancel(title=f"Movie Title",message=f"Is {search[i]} the movie you are looking for?"): id=search[i].movieID get_data(id) return id window=Tk() ia=im.IMDb() window.config(padx=50,pady=50) window.title("Movie Information App") canvas=Canvas(width=523,height=523) pic=PhotoImage(file="./IMDb_Jobs_Header_Mobile.png") bg_img=canvas.create_image(272,272,image=pic) canvas.grid(row=1,column=0) movie_name=simpledialog.askstring(title="Movie Information",prompt="Choose a film") movie_id=search_for_film(movie_name) window.mainloop()My current error code is:
RE: imdby package problem - lunacy90 - Sep-04-2023 (Sep-04-2023, 01:54 PM)deanhystad Wrote: Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error?ok so the code below now works. i forgot to add the parentheses after the object initialization. However i only get the title of the film back this time without errors. What i need is to get some kind of dictionary with the information about the film instead of just the title. do you know any packages or something that would help me acquire that? def get_data(movie_id): ia=im.IMDb() search=ia.get_movie(movie_id) print(search) RE: imdby package problem - deanhystad - Sep-04-2023 Looks like an internal package problem. Probably due to a change in the IMDB web page. Move on to a different package. This fails if there is no "h4" in your soup, or if none of the h4 contain the word 'release'. I hate it when there's no "h4" released in my soup. releases_index = [i for i in range(len(soup.select('h4'))) if 'release' in ' '.join(soup.select('h4')[i].text.split()).lower()][0]Well written web scraping code should never assume any search will find a match. And it is so easy to fix: releases = [i for i in range(len(soup.select('h4'))) if 'release' in ' '.join(soup.select('h4')[i].text.split()).lower()] release_index = releases[0] if releases else NoneStop using the "Reply" button unless your post directly references something in the post you are replying too. Use the "New Reply" button if your post just adds information. RE: imdby package problem - lunacy90 - Sep-04-2023 (Sep-04-2023, 02:33 PM)deanhystad Wrote: Looks like an internal package problem. Probably due to a change in the IMDB web page. Move on to a different package. ok.. wooooo. getting into the heavy stuff here. Can you check my comment above yours asking for any package or library or whatever that will help me retrieve some kind of json or dictionary file with the film information assigned by the movie id? Cause what i have now only gives me back the title which is useless RE: imdby package problem - deanhystad - Sep-04-2023 How about the one I mentioned in my first reply, Cinemagoer (used to be imdbPy)? That was last updated in May. RE: imdby package problem - lunacy90 - Sep-04-2023 (Sep-04-2023, 02:42 PM)deanhystad Wrote: How about the one I mentioned in my first reply, Cinemagoer (used to be imdbPy)? That was last updated in May. that was very helpful. after messing about a bit i decided to try and get the release year from Cinemagoer but i can't seem to be able to find the appropriate key for the release year of the feature. I tried printing the variable where i assign the get_movie function output but all i get is the title of the film. As you can see below i have access to the directors, genres and actors but i still cant find the year. ive tried 'year','release year' and 'release_year' to no avail def get_data(movie_id): ia=im.Cinemagoer() search=ia.get_movie(movie_id) directors=[director['name'] for director in search['directors']] genres=search["genres"] actors=[actor['name'] for actor in search['actors']][0:8] messagebox.showinfo(title=f"{search} Information",message=f"Director(s): {directors}\n" f"Genres: {genres}\n" f"Actors: {actors}") RE: imdby package problem - deanhystad - Sep-04-2023 Do you think guessing is the best strategy? Most object keep their instance variables in a dictionary named dict. Let's see what keys are in the __dict__. from imdb import Cinemagoer ia = Cinemagoer() search = ia.get_movie('0133093') # The Matrix print(*search.__dict__) Nothing all that promising there. Those attributes must reference some sort of collection. "data" looks promising.from imdb import Cinemagoer ia = Cinemagoer() search = ia.get_movie('0133093') # The Matrix print(type(search.data)) data is a dict. Lets look at the keys.from imdb import Cinemagoer ia = Cinemagoer() search = ia.get_movie('0133093') # The Matrix print(search.data.keys()) "original air date" looks interesting.from imdb import Cinemagoer ia = Cinemagoer() search = ia.get_movie('0133093') # The Matrix print(search.data['original air date']) Snooping around in the other fields may reveal more information. You'll have to snoop around.The best way to snoop is to use interactive python.
|