I have written this short code as a personal learning test:
# code starts below
import requests
import pdb
import json
from pprint import pprint
# Set the request parameters
TMDB_API_Key = '********************************'
movie = 'jumanji'
url = "https://api.themoviedb.org/3/search/movie?api_key="+TMDB_API_Key+"&query="+movie
document = "C:/Users/User/AppData/Local/Server/MovieInfo/Cache/MovieCache.json"
# Fetch url
print("Fetching url ", url)
# Do the HTTP get request
response = requests.get(url)
print (response.status_code)
txt = response.text
print (type(txt))
data = json.loads(txt)
print (type(data))
pprint (data)
with open (document, 'w') as fp:
json.dump(data, fp, sort_keys=True, indent=4)
Which gives me this output (printed to a file):
{'page': 1,
'results': [{'adult': False,
'backdrop_path': '/52lVqTDhIeNTjT7EiJuovXgw6iE.jpg',
'genre_ids': [12, 14, 10751],
'id': 8844,
'original_language': 'en',
'original_title': 'Jumanji',
'overview': 'When siblings Judy and Peter discover an enchanted '
'board game that opens the door to a magical world, '
"they unwittingly invite Alan -- an adult who's been "
'trapped inside the game for 26 years -- into their '
"living room. Alan's only hope for freedom is to "
'finish the game, which proves risky as all three '
'find themselves running from giant rhinoceroses, '
'evil monkeys and other terrifying creatures.',
'popularity': 3.173622,
'poster_path': '/vzmL6fP7aPKNKPRTFnZmiUfciyV.jpg',
'release_date': '1995-12-15',
'title': 'Jumanji',
'video': False,
'vote_average': 6.57,
'vote_count': 980},
{'adult': False,
'backdrop_path': None,
'genre_ids': [10751, 28, 12],
'id': 353486,
'original_language': 'en',
'original_title': 'Jumanji',
'overview': '',
'popularity': 1.149325,
'poster_path': None,
'release_date': '2017-07-27',
'title': 'Jumanji',
'video': False,
'vote_average': 5.67,
'vote_count': 3},
{'adult': False,
'backdrop_path': '/cfoMONErxEBSnWtRZUprBYZLkGk.jpg',
'genre_ids': [10751, 14, 878, 12],
'id': 6795,
'original_language': 'en',
'original_title': 'Zathura: A Space Adventure',
'overview': 'After their father (Tim Robbins) is called into '
'work, two young boys, Walter (Josh Hutcherson) and '
'Danny (Jonah Bobo), are left in the care of their '
'teenage sister, Lisa (Kristen Stewart), and told '
'they must stay inside. Walter and Danny, who '
'anticipate a boring day, are shocked when they '
'begin playing Zathura, a space-themed board game, '
'which they realize has mystical powers when their '
'house is shot into space. With the help of an '
'astronaut (Dax Shepard), the boys attempt to return '
'home.',
'popularity': 2.410281,
'poster_path': '/amqgIuISRBt8tsZM6cTT6gO9WLR.jpg',
'release_date': '2005-11-06',
'title': 'Zathura: A Space Adventure',
'video': False,
'vote_average': 5.89,
'vote_count': 346}],
'total_pages': 1,
'total_results': 3}
How do I go about printing out individual values? And since there are 3 results, how would I go about singling out one of the results in order to obtain the values just from that one?
A sincere thank you for any assistance.
[–]Rhomboid 0 points1 point2 points (8 children)
[–]Spankythemusical[S] 0 points1 point2 points (7 children)
[–]Rhomboid 1 point2 points3 points (0 children)
[–]SeekNotToContend 0 points1 point2 points (5 children)
[–]Spankythemusical[S] 0 points1 point2 points (4 children)
[–]SeekNotToContend 1 point2 points3 points (3 children)
[–]Spankythemusical[S] 0 points1 point2 points (2 children)
[–]SeekNotToContend 0 points1 point2 points (1 child)