Python Forum
IMDbPy "search_person" result cant be found in actors list in Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IMDbPy "search_person" result cant be found in actors list in Python
#3
The returned values from search_person is a list with instances of Person.
To get the name, use the square-brackets or the get method on the person instance.
The attribute item with the name is called name.

Counting example:
from imdb import Cinemagoer

first_name = "Arnold"
full_name = "Arnold Schwarzenegger"

query = Cinemagoer()
result = query.search_person(first_name)

names = [actor["name"] for actor in result]
for name in names:
    print(name)

print(full_name, "in results:", names.count(full_name))
You should read the docs: https://cinemagoer.readthedocs.io/en/lat...start.html

Here another example wich uses user input to search for a person and listing all the movies.
from imdb import Cinemagoer


# https://pypi.org/project/IMDbPY/
# IMDbPY is now cinemagoer
# pip install cinemagoer
# https://cinemagoer.github.io/


def ask_one_actor():
    user_input = input(
        f"Should only the first match of an actor listed (y/yes)?: "
    ).lower()
    if user_input in ("y", "yes"):
        return True
    else:
        return False


def main():
    query = Cinemagoer()
    show_only_one_actor = ask_one_actor()
    while True:
        actor = input("Please enter an actor name [q or whitespace to quit]: ").strip()
        # strip() removes whitespaces on left and right side of the str

        # condition to return which leaves the loop
        # a break could also be used, because there are
        # no further instructions are the while True loop

        if not actor.strip() or actor.lower() == "q":
            return

        # the method search_person returns a list
        # with persons (they are not str)

        # the result from query.search_person should be a list
        # index access should be possible
        for actor in query.search_person(actor):

            info_text = f"Query info for actor: {actor}"
            print(info_text)
            print("=" * len(info_text))

            query.update(actor)

            for movie in actor.get_titlesRefs():
                print(movie)

            # two newlines
            print("\n")

            if show_only_one_actor:
                break


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        print("\nQuit")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: IMDbPy "search_person" result cant be found in actors list in Python - by DeaD_EyE - Aug-04-2022, 09:29 AM

Forum Jump:

User Panel Messages

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