Working with the TMDb API

In [1]:
import requests

import os
import os.path
import sys
import importlib

if os.path.isdir(os.path.join("../../..", "modules")):
    module_dir = os.path.join("../../..", "modules")
else:
    module_dir = os.path.join("../..", "modules")

module_path = os.path.abspath(module_dir)
if not module_path in sys.path:
    sys.path.append(module_path)

import util
importlib.reload(util)
Out[1]:
<module 'util' from '/Users/tcbressoud/Dropbox/cs181-DataSystems/cs181-bressoud/f20_class/modules/util.py'>
In [2]:
tmdb_creds = util.read_creds("tmdb", ".", "creds.json")
In [5]:
apikey = ""
#apikey = tmdb_creds['apikey']
In [8]:
resourcepath = "/3/search/movie"
url = util.buildURL(resourcepath, "api.themoviedb.org")
print(url)
https://api.themoviedb.org/3/search/movie
In [11]:
paramsD = {}
response = requests.get(url, params=paramsD)
assert response.status_code == 200

search_results = response.json()
util.print_data(search_results)
{
  "page": 1,
  "total_results": 140,
  "total_pages": 7,
  "results": [
    {
      "popularity": 87.87,
      "vote_count": 14563,
      "video": false,
      "poster_path": "/6FfCtAuVAW8XJjZ7eWeLibRLWTw.jpg",
      "id": 11,
      "adult": false,
      "backdrop_path": "/zqkmTXzjkAgXmEWLRsY4UpTWCeo.jpg",
      "original_language": "en",
      "original_title": "Star Wars",
      "genre_ids": [
        12,
        28,
        878
      ],
      "title": "Star Wars",
      "vote_average": 8.2,
      "overview": "Princess Leia is captured and held hos...
      "release_date": "1977-05-25"
    },
    {
      "popularity": 179.587,
      "vote_count": 5881,
      "video": false,
      "poster_path": "/db32LaOibwEliAmSL2jjDF6oDdj.jpg",
      "id": 181812,
      "adult": false,
      "backdrop_path": "/SPkEiZGxq5aHWQ2Zw7AITwSEo2.jpg",
      "original_language": "en",
      "original_title": "Star Wars: The Rise of Skywalker",
      "genre_ids": [
        28,
        12,
        878
      ],
      "title": "Star Wars: The Rise of Skywalker",
      "vote_average": 6.6,
      "overview": "The surviving Resistance faces the Fir...
      "release_date": "2019-12-18"
    },
    {
      "popularity": 150.787,
      "vote_count": 6,
      "video": false,
      "poster_path": "/ksil1FjB7AfNk34LAti0636pyTd.jpg",
      "id": 749336,
      "adult": false,
      "backdrop_path": null,
      "original_language": "en",
      "original_title": "Star Wars: Wrath of the Mandalor...
      "genre_ids": [],
      "title": "Star Wars: Wrath of the Mandalorian",
      "vote_average": 8.3,
      "overview": "Years after the Clone Wars end, Darth ...
      "release_date": "2008-07-06"
    },
    {
      "popularity": 80.931,
      "id": 181808,
      "video": false,
      "vote_count": 11227,
      "vote_average": 6.9,
      "title": "Star Wars: The Last Jedi",
      "release_date": "2017-12-13",
      "original_language": "en",
      "original_title": "Star Wars: The Last Jedi",
      "genre_ids": [
        878,
        28,
        12
      ],
      "backdrop_path": "/5Iw7zQTHVRBOYpA0V6z0yypOPZh.jpg",
      "adult": false,
      "overview": "Rey develops her newly discovered abil...
      "poster_path": "/kOVEVeg59E0wsnXmF9nrh6OmWII.jpg"
    },
    {
      "popularity": 73.826,
      "vote_count": 5744,
      "video": false,
      "poster_path": "/4oD6VEccFkorEBTEDXtpLAaz0Rl.jpg",
      "id": 348350,
      "adult": false,
      "backdrop_path": "/7LZ0K4FsALrt7OeNIGOVLNuKQRU.jpg",
      "original_language": "en",
      "original_title": "Solo: A Star Wars Story",
      "genre_ids": [
        12,
        878
      ],
      "title": "Solo: A Star Wars Story",
      "vote_average": 6.6,
      "overview": "Through a series of daring escapades d...
      "release_date": "2018-05-15"
    },
    {
      "popularity": 73.98,
      "vote_count": 15102,
      "video": false,
      "poster_path": "/wqnLdwVXoBjKibFRR5U3y0aDUhs.jpg",
      "id": 140607,
      "adult": false,
      "backdrop_path": "/k6EOrckWFuz7I4z4wiRwz8zsj4H.jpg",
      "original_language": "en",
      "original_title": "Star Wars: The Force Awakens",
      "genre_ids": [
        28,
        12,
        878,
        14
      ],
      "title": "Star Wars: The Force Awakens",
      "vote_average": 7.4,
      "overview": "Thirty years after defeating the Galac...
      "release_date": "2015-12-15"
    },
    {
      "popularity": 54.583,
      "vote_count": 11467,
      "video": false,
      "poster_path": "/5jX3p0apUG5bkMHtnKZch0xpkBS.jpg",
      "id": 330459,
      "adult": false,
      "backdrop_path": "/6t8ES1d12OzWyCGxBeDYLHoaDrT.jpg",
      "original_language": "en",
      "original_title": "Rogue One: A Star Wars Story",
      "genre_ids": [
        28,
        12,
        878
      ],
      "title": "Rogue One: A Star Wars Story",
      "vote_average": 7.5,
      "overview": "A rogue band of resistance fighters un...
      "release_date": "2016-12-14"
    },
    {
      "popularity": 37.327,
      "vote_count": 1160,
      "video": false,
      "poster_path": "/veee7dll1xMwK14dGt0xsQekYYs.jpg",
      "id": 12180,
      "adult": false,
      "backdrop_path": "/sNNFLEcAuy4C3RyXCnKoArn7Aty.jpg",
      "original_language": "en",
      "original_title": "Star Wars: The Clone Wars",
      "genre_ids": [
        28,
        12,
        16,
        878
      ],
      "title": "Star Wars: The Clone Wars",
      "vote_average": 5.9,
      "overview": "Set between Episode II and III, The Cl...
      "release_date": "2008-08-05"
    },
    {
      "popularity": 49.52,
      "vote_count": 10297,
      "video": false,
      "poster_path": "/6wkfovpn7Eq8dYNKaG5PY3q2oq6.jpg",
      "id": 1893,
      "adult": false,
      "backdrop_path": "/qDEvctVfAheD7x9Rzz8xcFRAGAU.jpg",
      "original_language": "en",
      "original_title": "Star Wars: Episode I - The Phant...
      "genre_ids": [
        12,
        28,
        878
      ],
      "title": "Star Wars: Episode I - The Phantom Menace",
      "vote_average": 6.5,
      "overview": "Anakin Skywalker, a young slave strong...
      "release_date": "1999-05-19"
    },
    {
      "popularity": 16.319,
      "id": 392216,
      "video": false,
      "vote_count": 77,
      "vote_average": 7.2,
      "title": "Phineas and Ferb: Star Wars",
      "release_date": "2014-07-26",
      "original_language": "en",
      "original_title": "Phineas and Ferb: Star Wars",
      "genre_ids": [
        28,
        16,
        35,
        10751,
        878,
        10402
      ],
      "backdrop_path": "/uNjBnOmdjZoiWTLQ938YJZ1cYVU.jpg",
      "adult": false,
      "overview": "Phineas and Ferb are peacefully living...
      "poster_path": "/xomphpz7MIasqVluPX83TjoTL8G.jpg"
    },
    {
      "popularity": 44.265,
      "vote_count": 9640,
      "video": false,
      "poster_path": "/xfSAoBEm9MNBjmlNcDYLvLSMlnq.jpg",
      "id": 1895,
      "adult": false,
      "backdrop_path": "/vgGJ9ThoKjFbQHbAeI29NsbT2lK.jpg",
      "original_language": "en",
      "original_title": "Star Wars: Episode III - Revenge...
      "genre_ids": [
        878,
        12,
        28
      ],
      "title": "Star Wars: Episode III - Revenge of the S...
      "vote_average": 7.3,
      "overview": "The evil Darth Sidious enacts his fina...
      "release_date": "2005-05-17"
    },
    {
      "popularity": 13.168,
      "vote_count": 15,
      "video": false,
      "poster_path": "/ocA0ECiFoB4d1HITyEDQlLk7x84.jpg",
      "id": 667574,
      "adult": false,
      "backdrop_path": "/c8XIFuJCPTtTJdSRpqnUoMr6eK1.jpg",
      "original_language": "en",
      "original_title": "Battle Star Wars",
      "genre_ids": [
        878
      ],
      "title": "Battle Star Wars",
      "vote_average": 4.4,
      "overview": "When the leader of the evil Coalition ...
      "release_date": "2020-01-28"
    },
    {
      "popularity": 41.546,
      "vote_count": 9298,
      "video": false,
      "poster_path": "/oZNPzxqM2s5DyVWab09NTQScDQt.jpg",
      "id": 1894,
      "adult": false,
      "backdrop_path": "/msYmRFJfXy0zsFd73PAEqdetKpO.jpg",
      "original_language": "en",
      "original_title": "Star Wars: Episode II - Attack o...
      "genre_ids": [
        12,
        28,
        878
      ],
      "title": "Star Wars: Episode II - Attack of the Clo...
      "vote_average": 6.5,
      "overview": "Following an assassination attempt on ...
      "release_date": "2002-05-15"
    },
    {
      "popularity": 29.327,
      "vote_count": 1,
      "video": false,
      "poster_path": "/mfPT0R0pBmC09P3wFoIGxNHQt82.jpg",
      "id": 732670,
      "adult": false,
      "backdrop_path": "/uKdZCAlndm6eD0in4B0xBgVeizK.jpg",
      "original_language": "en",
      "original_title": "The Lego Star Wars Holiday Speci...
      "genre_ids": [
        16,
        12,
        35,
        10751,
        878
      ],
      "title": "The Lego Star Wars Holiday Special",
      "vote_average": 10,
      "overview": "Rey's visit to a mysterious Jedi Templ...
      "release_date": "2020-11-17"
    },
    {
      "popularity": 13.798,
      "vote_count": 159,
      "video": false,
      "poster_path": "/h44WN4mVJ6wEpJgLaaNoFjv0NAo.jpg",
      "id": 42979,
      "adult": false,
      "backdrop_path": null,
      "original_language": "en",
      "original_title": "Robot Chicken: Star Wars",
      "genre_ids": [
        16,
        35,
        878
      ],
      "title": "Robot Chicken: Star Wars",
      "vote_average": 7.3,
      "overview": "Fans of Adult Swim's \"Robot Chicken\"...
      "release_date": "2007-07-17"
    },
    {
      "popularity": 16.814,
      "vote_count": 3,
      "video": false,
      "poster_path": "/fvw9W7ds0Q51hQIbS7JoUBqL3tK.jpg",
      "id": 435365,
      "adult": false,
      "backdrop_path": null,
      "original_language": "en",
      "original_title": "The Story of Star Wars",
      "genre_ids": [
        99
      ],
      "title": "The Story of Star Wars",
      "vote_average": 8.3,
      "overview": "The Skywalker family is at the heart o...
      "release_date": "2004-08-18"
    },
    {
      "popularity": 14.777,
      "vote_count": 282,
      "video": false,
      "poster_path": "/e9PjmRR7XgFx7Vkq42Q70BLfFt3.jpg",
      "id": 74849,
      "adult": false,
      "backdrop_path": "/ae9xlnkS2qb5Dy9Mtlu68AWh42O.jpg",
      "original_language": "en",
      "original_title": "The Star Wars Holiday Special",
      "genre_ids": [
        12,
        35,
        10751,
        878,
        10770
      ],
      "title": "The Star Wars Holiday Special",
      "vote_average": 3.1,
      "overview": "Luke Skywalker and Han Solo battle evi...
      "release_date": "1978-12-01"
    },
    {
      "popularity": 11.248,
      "vote_count": 10,
      "video": false,
      "poster_path": "/iLR4myu0RED1JYQGEcJpOM7CWAN.jpg",
      "id": 72448,
      "adult": false,
      "backdrop_path": "/e8OhGGKQmLXwyroNwXrXncejm5c.jpg",
      "original_language": "en",
      "original_title": "Star Wars: A Musical Journey",
      "genre_ids": [
        10402
      ],
      "title": "Star Wars: A Musical Journey",
      "vote_average": 7,
      "overview": "Actor Ian McDiarmid introduces several...
      "release_date": "2005-05-03"
    },
    {
      "popularity": 13.485,
      "vote_count": 95,
      "video": false,
      "poster_path": "/mi2lVho2zpfwcxI6yC1QYJi435D.jpg",
      "id": 51888,
      "adult": false,
      "backdrop_path": null,
      "original_language": "en",
      "original_title": "Robot Chicken: Star Wars Episode...
      "genre_ids": [
        16,
        35,
        878
      ],
      "title": "Robot Chicken: Star Wars Episode III",
      "vote_average": 7.4,
      "overview": "Robot Chicken: Star Wars Episode III, ...
      "release_date": "2010-12-19"
    },
    {
      "popularity": 6.74,
      "id": 436621,
      "video": false,
      "vote_count": 0,
      "vote_average": 0,
      "title": "Star Wars : L'incroyable L\u00e9gende",
      "release_date": "2015-11-25",
      "original_language": "fr",
      "original_title": "Star Wars : L'incroyable L\u00e9...
      "genre_ids": [
        99
      ],
      "backdrop_path": null,
      "adult": false,
      "overview": "",
      "poster_path": "/nsZIPT5pyvXHftO8bH4o7LU8Vch.jpg"
    }
  ]
}
In [ ]:
 
In [ ]: