{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Working with the TMDb API" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "nbgrader": { "grade": false, "grade_id": "cell-b9abcf27cf7faf8f", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "\n", "import os\n", "import os.path\n", "import sys\n", "import importlib\n", "\n", "if os.path.isdir(os.path.join(\"../../..\", \"modules\")):\n", " module_dir = os.path.join(\"../../..\", \"modules\")\n", "else:\n", " module_dir = os.path.join(\"../..\", \"modules\")\n", "\n", "module_path = os.path.abspath(module_dir)\n", "if not module_path in sys.path:\n", " sys.path.append(module_path)\n", "\n", "import util\n", "importlib.reload(util)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Helpful Links\n", "\n", "- TMDB Login Page: https://themoviedb.org/login\n", "- API Settings: https://www.themoviedb.org/settings/api\n", "- API Documentation Top Level: https://www.themoviedb.org/documentation/api\n", "- API Endpoints: https://developers.themoviedb.org/3/getting-started/introduction" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "tmdb_creds = util.read_creds(\"tmdb\", \".\", \"creds.json\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "apikey = \"\"\n", "#apikey = tmdb_creds['apikey']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "https://api.themoviedb.org/3/search/movie\n" ] } ], "source": [ "resourcepath = \"/3/search/movie\"\n", "url = util.buildURL(resourcepath, \"api.themoviedb.org\")\n", "print(url)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{\n", " \"page\": 1,\n", " \"total_results\": 140,\n", " \"total_pages\": 7,\n", " \"results\": [\n", " {\n", " \"popularity\": 87.87,\n", " \"vote_count\": 14563,\n", " \"video\": false,\n", " \"poster_path\": \"/6FfCtAuVAW8XJjZ7eWeLibRLWTw.jpg\",\n", " \"id\": 11,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/zqkmTXzjkAgXmEWLRsY4UpTWCeo.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars\",\n", " \"genre_ids\": [\n", " 12,\n", " 28,\n", " 878\n", " ],\n", " \"title\": \"Star Wars\",\n", " \"vote_average\": 8.2,\n", " \"overview\": \"Princess Leia is captured and held hos...\n", " \"release_date\": \"1977-05-25\"\n", " },\n", " {\n", " \"popularity\": 179.587,\n", " \"vote_count\": 5881,\n", " \"video\": false,\n", " \"poster_path\": \"/db32LaOibwEliAmSL2jjDF6oDdj.jpg\",\n", " \"id\": 181812,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/SPkEiZGxq5aHWQ2Zw7AITwSEo2.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: The Rise of Skywalker\",\n", " \"genre_ids\": [\n", " 28,\n", " 12,\n", " 878\n", " ],\n", " \"title\": \"Star Wars: The Rise of Skywalker\",\n", " \"vote_average\": 6.6,\n", " \"overview\": \"The surviving Resistance faces the Fir...\n", " \"release_date\": \"2019-12-18\"\n", " },\n", " {\n", " \"popularity\": 150.787,\n", " \"vote_count\": 6,\n", " \"video\": false,\n", " \"poster_path\": \"/ksil1FjB7AfNk34LAti0636pyTd.jpg\",\n", " \"id\": 749336,\n", " \"adult\": false,\n", " \"backdrop_path\": null,\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: Wrath of the Mandalor...\n", " \"genre_ids\": [],\n", " \"title\": \"Star Wars: Wrath of the Mandalorian\",\n", " \"vote_average\": 8.3,\n", " \"overview\": \"Years after the Clone Wars end, Darth ...\n", " \"release_date\": \"2008-07-06\"\n", " },\n", " {\n", " \"popularity\": 80.931,\n", " \"id\": 181808,\n", " \"video\": false,\n", " \"vote_count\": 11227,\n", " \"vote_average\": 6.9,\n", " \"title\": \"Star Wars: The Last Jedi\",\n", " \"release_date\": \"2017-12-13\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: The Last Jedi\",\n", " \"genre_ids\": [\n", " 878,\n", " 28,\n", " 12\n", " ],\n", " \"backdrop_path\": \"/5Iw7zQTHVRBOYpA0V6z0yypOPZh.jpg\",\n", " \"adult\": false,\n", " \"overview\": \"Rey develops her newly discovered abil...\n", " \"poster_path\": \"/kOVEVeg59E0wsnXmF9nrh6OmWII.jpg\"\n", " },\n", " {\n", " \"popularity\": 73.826,\n", " \"vote_count\": 5744,\n", " \"video\": false,\n", " \"poster_path\": \"/4oD6VEccFkorEBTEDXtpLAaz0Rl.jpg\",\n", " \"id\": 348350,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/7LZ0K4FsALrt7OeNIGOVLNuKQRU.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Solo: A Star Wars Story\",\n", " \"genre_ids\": [\n", " 12,\n", " 878\n", " ],\n", " \"title\": \"Solo: A Star Wars Story\",\n", " \"vote_average\": 6.6,\n", " \"overview\": \"Through a series of daring escapades d...\n", " \"release_date\": \"2018-05-15\"\n", " },\n", " {\n", " \"popularity\": 73.98,\n", " \"vote_count\": 15102,\n", " \"video\": false,\n", " \"poster_path\": \"/wqnLdwVXoBjKibFRR5U3y0aDUhs.jpg\",\n", " \"id\": 140607,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/k6EOrckWFuz7I4z4wiRwz8zsj4H.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: The Force Awakens\",\n", " \"genre_ids\": [\n", " 28,\n", " 12,\n", " 878,\n", " 14\n", " ],\n", " \"title\": \"Star Wars: The Force Awakens\",\n", " \"vote_average\": 7.4,\n", " \"overview\": \"Thirty years after defeating the Galac...\n", " \"release_date\": \"2015-12-15\"\n", " },\n", " {\n", " \"popularity\": 54.583,\n", " \"vote_count\": 11467,\n", " \"video\": false,\n", " \"poster_path\": \"/5jX3p0apUG5bkMHtnKZch0xpkBS.jpg\",\n", " \"id\": 330459,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/6t8ES1d12OzWyCGxBeDYLHoaDrT.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Rogue One: A Star Wars Story\",\n", " \"genre_ids\": [\n", " 28,\n", " 12,\n", " 878\n", " ],\n", " \"title\": \"Rogue One: A Star Wars Story\",\n", " \"vote_average\": 7.5,\n", " \"overview\": \"A rogue band of resistance fighters un...\n", " \"release_date\": \"2016-12-14\"\n", " },\n", " {\n", " \"popularity\": 37.327,\n", " \"vote_count\": 1160,\n", " \"video\": false,\n", " \"poster_path\": \"/veee7dll1xMwK14dGt0xsQekYYs.jpg\",\n", " \"id\": 12180,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/sNNFLEcAuy4C3RyXCnKoArn7Aty.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: The Clone Wars\",\n", " \"genre_ids\": [\n", " 28,\n", " 12,\n", " 16,\n", " 878\n", " ],\n", " \"title\": \"Star Wars: The Clone Wars\",\n", " \"vote_average\": 5.9,\n", " \"overview\": \"Set between Episode II and III, The Cl...\n", " \"release_date\": \"2008-08-05\"\n", " },\n", " {\n", " \"popularity\": 49.52,\n", " \"vote_count\": 10297,\n", " \"video\": false,\n", " \"poster_path\": \"/6wkfovpn7Eq8dYNKaG5PY3q2oq6.jpg\",\n", " \"id\": 1893,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/qDEvctVfAheD7x9Rzz8xcFRAGAU.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: Episode I - The Phant...\n", " \"genre_ids\": [\n", " 12,\n", " 28,\n", " 878\n", " ],\n", " \"title\": \"Star Wars: Episode I - The Phantom Menace\",\n", " \"vote_average\": 6.5,\n", " \"overview\": \"Anakin Skywalker, a young slave strong...\n", " \"release_date\": \"1999-05-19\"\n", " },\n", " {\n", " \"popularity\": 16.319,\n", " \"id\": 392216,\n", " \"video\": false,\n", " \"vote_count\": 77,\n", " \"vote_average\": 7.2,\n", " \"title\": \"Phineas and Ferb: Star Wars\",\n", " \"release_date\": \"2014-07-26\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Phineas and Ferb: Star Wars\",\n", " \"genre_ids\": [\n", " 28,\n", " 16,\n", " 35,\n", " 10751,\n", " 878,\n", " 10402\n", " ],\n", " \"backdrop_path\": \"/uNjBnOmdjZoiWTLQ938YJZ1cYVU.jpg\",\n", " \"adult\": false,\n", " \"overview\": \"Phineas and Ferb are peacefully living...\n", " \"poster_path\": \"/xomphpz7MIasqVluPX83TjoTL8G.jpg\"\n", " },\n", " {\n", " \"popularity\": 44.265,\n", " \"vote_count\": 9640,\n", " \"video\": false,\n", " \"poster_path\": \"/xfSAoBEm9MNBjmlNcDYLvLSMlnq.jpg\",\n", " \"id\": 1895,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/vgGJ9ThoKjFbQHbAeI29NsbT2lK.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: Episode III - Revenge...\n", " \"genre_ids\": [\n", " 878,\n", " 12,\n", " 28\n", " ],\n", " \"title\": \"Star Wars: Episode III - Revenge of the S...\n", " \"vote_average\": 7.3,\n", " \"overview\": \"The evil Darth Sidious enacts his fina...\n", " \"release_date\": \"2005-05-17\"\n", " },\n", " {\n", " \"popularity\": 13.168,\n", " \"vote_count\": 15,\n", " \"video\": false,\n", " \"poster_path\": \"/ocA0ECiFoB4d1HITyEDQlLk7x84.jpg\",\n", " \"id\": 667574,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/c8XIFuJCPTtTJdSRpqnUoMr6eK1.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Battle Star Wars\",\n", " \"genre_ids\": [\n", " 878\n", " ],\n", " \"title\": \"Battle Star Wars\",\n", " \"vote_average\": 4.4,\n", " \"overview\": \"When the leader of the evil Coalition ...\n", " \"release_date\": \"2020-01-28\"\n", " },\n", " {\n", " \"popularity\": 41.546,\n", " \"vote_count\": 9298,\n", " \"video\": false,\n", " \"poster_path\": \"/oZNPzxqM2s5DyVWab09NTQScDQt.jpg\",\n", " \"id\": 1894,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/msYmRFJfXy0zsFd73PAEqdetKpO.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: Episode II - Attack o...\n", " \"genre_ids\": [\n", " 12,\n", " 28,\n", " 878\n", " ],\n", " \"title\": \"Star Wars: Episode II - Attack of the Clo...\n", " \"vote_average\": 6.5,\n", " \"overview\": \"Following an assassination attempt on ...\n", " \"release_date\": \"2002-05-15\"\n", " },\n", " {\n", " \"popularity\": 29.327,\n", " \"vote_count\": 1,\n", " \"video\": false,\n", " \"poster_path\": \"/mfPT0R0pBmC09P3wFoIGxNHQt82.jpg\",\n", " \"id\": 732670,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/uKdZCAlndm6eD0in4B0xBgVeizK.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"The Lego Star Wars Holiday Speci...\n", " \"genre_ids\": [\n", " 16,\n", " 12,\n", " 35,\n", " 10751,\n", " 878\n", " ],\n", " \"title\": \"The Lego Star Wars Holiday Special\",\n", " \"vote_average\": 10,\n", " \"overview\": \"Rey's visit to a mysterious Jedi Templ...\n", " \"release_date\": \"2020-11-17\"\n", " },\n", " {\n", " \"popularity\": 13.798,\n", " \"vote_count\": 159,\n", " \"video\": false,\n", " \"poster_path\": \"/h44WN4mVJ6wEpJgLaaNoFjv0NAo.jpg\",\n", " \"id\": 42979,\n", " \"adult\": false,\n", " \"backdrop_path\": null,\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Robot Chicken: Star Wars\",\n", " \"genre_ids\": [\n", " 16,\n", " 35,\n", " 878\n", " ],\n", " \"title\": \"Robot Chicken: Star Wars\",\n", " \"vote_average\": 7.3,\n", " \"overview\": \"Fans of Adult Swim's \\\"Robot Chicken\\\"...\n", " \"release_date\": \"2007-07-17\"\n", " },\n", " {\n", " \"popularity\": 16.814,\n", " \"vote_count\": 3,\n", " \"video\": false,\n", " \"poster_path\": \"/fvw9W7ds0Q51hQIbS7JoUBqL3tK.jpg\",\n", " \"id\": 435365,\n", " \"adult\": false,\n", " \"backdrop_path\": null,\n", " \"original_language\": \"en\",\n", " \"original_title\": \"The Story of Star Wars\",\n", " \"genre_ids\": [\n", " 99\n", " ],\n", " \"title\": \"The Story of Star Wars\",\n", " \"vote_average\": 8.3,\n", " \"overview\": \"The Skywalker family is at the heart o...\n", " \"release_date\": \"2004-08-18\"\n", " },\n", " {\n", " \"popularity\": 14.777,\n", " \"vote_count\": 282,\n", " \"video\": false,\n", " \"poster_path\": \"/e9PjmRR7XgFx7Vkq42Q70BLfFt3.jpg\",\n", " \"id\": 74849,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/ae9xlnkS2qb5Dy9Mtlu68AWh42O.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"The Star Wars Holiday Special\",\n", " \"genre_ids\": [\n", " 12,\n", " 35,\n", " 10751,\n", " 878,\n", " 10770\n", " ],\n", " \"title\": \"The Star Wars Holiday Special\",\n", " \"vote_average\": 3.1,\n", " \"overview\": \"Luke Skywalker and Han Solo battle evi...\n", " \"release_date\": \"1978-12-01\"\n", " },\n", " {\n", " \"popularity\": 11.248,\n", " \"vote_count\": 10,\n", " \"video\": false,\n", " \"poster_path\": \"/iLR4myu0RED1JYQGEcJpOM7CWAN.jpg\",\n", " \"id\": 72448,\n", " \"adult\": false,\n", " \"backdrop_path\": \"/e8OhGGKQmLXwyroNwXrXncejm5c.jpg\",\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Star Wars: A Musical Journey\",\n", " \"genre_ids\": [\n", " 10402\n", " ],\n", " \"title\": \"Star Wars: A Musical Journey\",\n", " \"vote_average\": 7,\n", " \"overview\": \"Actor Ian McDiarmid introduces several...\n", " \"release_date\": \"2005-05-03\"\n", " },\n", " {\n", " \"popularity\": 13.485,\n", " \"vote_count\": 95,\n", " \"video\": false,\n", " \"poster_path\": \"/mi2lVho2zpfwcxI6yC1QYJi435D.jpg\",\n", " \"id\": 51888,\n", " \"adult\": false,\n", " \"backdrop_path\": null,\n", " \"original_language\": \"en\",\n", " \"original_title\": \"Robot Chicken: Star Wars Episode...\n", " \"genre_ids\": [\n", " 16,\n", " 35,\n", " 878\n", " ],\n", " \"title\": \"Robot Chicken: Star Wars Episode III\",\n", " \"vote_average\": 7.4,\n", " \"overview\": \"Robot Chicken: Star Wars Episode III, ...\n", " \"release_date\": \"2010-12-19\"\n", " },\n", " {\n", " \"popularity\": 6.74,\n", " \"id\": 436621,\n", " \"video\": false,\n", " \"vote_count\": 0,\n", " \"vote_average\": 0,\n", " \"title\": \"Star Wars : L'incroyable L\\u00e9gende\",\n", " \"release_date\": \"2015-11-25\",\n", " \"original_language\": \"fr\",\n", " \"original_title\": \"Star Wars : L'incroyable L\\u00e9...\n", " \"genre_ids\": [\n", " 99\n", " ],\n", " \"backdrop_path\": null,\n", " \"adult\": false,\n", " \"overview\": \"\",\n", " \"poster_path\": \"/nsZIPT5pyvXHftO8bH4o7LU8Vch.jpg\"\n", " }\n", " ]\n", "}\n" ] } ], "source": [ "paramsD = {}\n", "response = requests.get(url, params=paramsD)\n", "assert response.status_code == 200\n", "\n", "search_results = response.json()\n", "util.print_data(search_results)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }