Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tmdbsimple as tmdb
- tmdb.API_KEY = 'xxxxxxxxxxxxxxx'
- PERSON_NAMES = [
- 'Bill Murray',
- 'Adam Sandler',
- 'Robin Williams',
- 'Jack Nicholson',
- 'Shia LaBeouf',
- 'Tom Hanks',
- 'Winona Ryder',
- 'Jack Black',
- 'Dwayne Johnson',
- 'Mel Gibson',
- 'Nicolas Cage',
- 'Keanu Reeves',
- 'Brittany Murphy',
- 'David Spade',
- 'Chris Farley',
- 'Johnny Depp',
- 'Tom Cruise',
- 'Reese Witherspoon',
- 'Leonardo DiCaprio',
- 'Morgan Freeman',
- 'Samuel Jackson',
- 'Denzel Washington',
- 'Will Smith',
- 'Ben Affleck',
- 'Matt Damon',
- 'Vince Vaughn',
- 'Steve Carell',
- 'Sylvester Stallone',
- 'Arnold Schwarzenegger',
- 'Ben Stiller',
- 'Owen Wilson',
- 'John Candy',
- 'Dan Aykroyd',
- 'Corey Feldman',
- 'Ashton Kutcher',
- 'Seann Scott',
- 'Johnny Knoxville',
- 'Matthew Lillard',
- 'Dax Shepard',
- 'Seth Green',
- 'Alfonso Ribeiro',
- 'James Avery',
- 'Kathy Bates',
- 'Harland Williams',
- 'Rip Torn',
- 'Zac Efron',
- 'Matthew McConaughey',
- 'Robert Pattinson',
- 'Anne Hathaway',
- 'Jake Gyllenhaal',
- 'Jon Heder',
- 'Christina Ricci',
- 'Julia Roberts',
- 'Brad Pitt',
- 'Michael Caine',
- 'Christian Bale',
- 'Gary Oldman',
- 'Al Pacino',
- 'Edward Norton',
- 'Harrison Ford',
- 'Cillian Murphy',
- 'Bruce Willis',
- 'Robert Duvall',
- 'Sean Connery',
- 'Steve Buscemi',
- 'Liam Neeson',
- 'Russell Crowe',
- 'Clint Eastwood',
- 'Ryan Gosling',
- 'Bradley Cooper',
- 'Heath Ledger',
- 'Patrick Swayze',
- 'Orlando Bloom',
- 'Joaquin Phoenix',
- 'Robert Downey Jr.',
- 'Daniel Craig',
- 'Mark Wahlberg',
- 'Jim Carrey',
- 'Katharine Hepburn',
- 'Jessica Lange',
- 'Meryl Streep',
- 'Jodie Foster',
- 'Nicole Kidman',
- 'Sandra Bullock',
- 'Jennifer Lawrence',
- 'Natalie Portman',
- 'Julie Andrews',
- 'Whoopi Goldberg',
- 'Angelina Jolie',
- 'Emma Watson',
- 'Emma Stone',
- 'Lena Headey',
- 'Ellen Page',
- 'Jennifer Aniston',
- 'Luke Wilson',
- 'Terry Crews',
- ]
- ##########################################################
- # Helper functions
- ##########################################################
- # Fetches the `tmdb.People` object of a given person"
- def get_person(name):
- search = tmdb.Search()
- result = search.person(query=name)
- if len(result['results']) == 0:
- raise ValueError('Invalid person: %s' % name)
- most_popular_result = max(result['results'], key=lambda d: d['popularity'])
- person_id = most_popular_result['id']
- person = tmdb.People(person_id)
- return person
- # Fetches all movie ids associated with a `tmdb.People` person.
- def get_all_movie_ids_from_person(person):
- movie_credits = person.movie_credits()
- movie_ids = set()
- for movie in movie_credits['cast']:
- movie_ids.add(movie['id'])
- for movie in movie_credits['crew']:
- movie_ids.add(movie['id'])
- return movie_ids
- def get_movie_titles(movie_ids):
- movie_names = set()
- for id in movie_ids:
- movie = tmdb.Movies(id)
- movie_title = movie.info()['original_title']
- print(movie_title)
- movie_names.add(movie_title)
- return movie_names
- def get_all_movie_names():
- movie_ids = set()
- for name in PERSON_NAMES:
- person = get_person(name)
- person_movie_ids = get_all_movie_ids_from_person(person)
- movie_ids |= person_movie_ids
- movie_names = get_movie_titles(movie_ids)
- return movie_names
- ##########################################################
- # Main function
- ##########################################################
- def main():
- get_all_movie_names()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement