Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. import tmdbsimple as tmdb
  2.  
  3. tmdb.API_KEY = 'xxxxxxxxxxxxxxx'
  4.  
  5. PERSON_NAMES = [
  6. 'Bill Murray',
  7. 'Adam Sandler',
  8. 'Robin Williams',
  9. 'Jack Nicholson',
  10. 'Shia LaBeouf',
  11. 'Tom Hanks',
  12. 'Winona Ryder',
  13. 'Jack Black',
  14. 'Dwayne Johnson',
  15. 'Mel Gibson',
  16. 'Nicolas Cage',
  17. 'Keanu Reeves',
  18. 'Brittany Murphy',
  19. 'David Spade',
  20. 'Chris Farley',
  21. 'Johnny Depp',
  22. 'Tom Cruise',
  23. 'Reese Witherspoon',
  24. 'Leonardo DiCaprio',
  25. 'Morgan Freeman',
  26. 'Samuel Jackson',
  27. 'Denzel Washington',
  28. 'Will Smith',
  29. 'Ben Affleck',
  30. 'Matt Damon',
  31. 'Vince Vaughn',
  32. 'Steve Carell',
  33. 'Sylvester Stallone',
  34. 'Arnold Schwarzenegger',
  35. 'Ben Stiller',
  36. 'Owen Wilson',
  37. 'John Candy',
  38. 'Dan Aykroyd',
  39. 'Corey Feldman',
  40. 'Ashton Kutcher',
  41. 'Seann Scott',
  42. 'Johnny Knoxville',
  43. 'Matthew Lillard',
  44. 'Dax Shepard',
  45. 'Seth Green',
  46. 'Alfonso Ribeiro',
  47. 'James Avery',
  48. 'Kathy Bates',
  49. 'Harland Williams',
  50. 'Rip Torn',
  51. 'Zac Efron',
  52. 'Matthew McConaughey',
  53. 'Robert Pattinson',
  54. 'Anne Hathaway',
  55. 'Jake Gyllenhaal',
  56. 'Jon Heder',
  57. 'Christina Ricci',
  58. 'Julia Roberts',
  59. 'Brad Pitt',
  60. 'Michael Caine',
  61. 'Christian Bale',
  62. 'Gary Oldman',
  63. 'Al Pacino',
  64. 'Edward Norton',
  65. 'Harrison Ford',
  66. 'Cillian Murphy',
  67. 'Bruce Willis',
  68. 'Robert Duvall',
  69. 'Sean Connery',
  70. 'Steve Buscemi',
  71. 'Liam Neeson',
  72. 'Russell Crowe',
  73. 'Clint Eastwood',
  74. 'Ryan Gosling',
  75. 'Bradley Cooper',
  76. 'Heath Ledger',
  77. 'Patrick Swayze',
  78. 'Orlando Bloom',
  79. 'Joaquin Phoenix',
  80. 'Robert Downey Jr.',
  81. 'Daniel Craig',
  82. 'Mark Wahlberg',
  83. 'Jim Carrey',
  84. 'Katharine Hepburn',
  85. 'Jessica Lange',
  86. 'Meryl Streep',
  87. 'Jodie Foster',
  88. 'Nicole Kidman',
  89. 'Sandra Bullock',
  90. 'Jennifer Lawrence',
  91. 'Natalie Portman',
  92. 'Julie Andrews',
  93. 'Whoopi Goldberg',
  94. 'Angelina Jolie',
  95. 'Emma Watson',
  96. 'Emma Stone',
  97. 'Lena Headey',
  98. 'Ellen Page',
  99. 'Jennifer Aniston',
  100. 'Luke Wilson',
  101. 'Terry Crews',
  102. ]
  103.  
  104. ##########################################################
  105. # Helper functions
  106. ##########################################################
  107.  
  108.  
  109. # Fetches the `tmdb.People` object of a given person"
  110. def get_person(name):
  111. search = tmdb.Search()
  112. result = search.person(query=name)
  113.  
  114. if len(result['results']) == 0:
  115. raise ValueError('Invalid person: %s' % name)
  116.  
  117. most_popular_result = max(result['results'], key=lambda d: d['popularity'])
  118.  
  119. person_id = most_popular_result['id']
  120. person = tmdb.People(person_id)
  121.  
  122. return person
  123.  
  124. # Fetches all movie ids associated with a `tmdb.People` person.
  125. def get_all_movie_ids_from_person(person):
  126. movie_credits = person.movie_credits()
  127. movie_ids = set()
  128.  
  129. for movie in movie_credits['cast']:
  130. movie_ids.add(movie['id'])
  131. for movie in movie_credits['crew']:
  132. movie_ids.add(movie['id'])
  133.  
  134. return movie_ids
  135.  
  136.  
  137. def get_movie_titles(movie_ids):
  138. movie_names = set()
  139.  
  140. for id in movie_ids:
  141. movie = tmdb.Movies(id)
  142. movie_title = movie.info()['original_title']
  143. print(movie_title)
  144.  
  145. movie_names.add(movie_title)
  146.  
  147. return movie_names
  148.  
  149.  
  150. def get_all_movie_names():
  151. movie_ids = set()
  152.  
  153. for name in PERSON_NAMES:
  154. person = get_person(name)
  155. person_movie_ids = get_all_movie_ids_from_person(person)
  156.  
  157. movie_ids |= person_movie_ids
  158.  
  159. movie_names = get_movie_titles(movie_ids)
  160.  
  161. return movie_names
  162.  
  163.  
  164. ##########################################################
  165. # Main function
  166. ##########################################################
  167.  
  168. def main():
  169. get_all_movie_names()
  170.  
  171.  
  172. if __name__ == "__main__":
  173. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement