In this video I'll show you how to quickly and easily access web apis and convert the resulting JSON data into a Python dictionary, pull the relevant information out, and print it. We'll be using TV Maze to get information about various TV shows.
Links:
TV Maze API Info: https://www.tvmaze.com/api
JSON: https://www.json.org/json-en.html
Code:
import requests
import json
import pprint
url = "http://api.tvmaze.com/singlesearch/shows"
show = input("Please input a show name. ")
params = {"q":show}
response = requests.get(url, params)
if response.status_code == 200:
data = json.loads(response.text)
pprint.pprint(data)
name = data['name']
premiered = data['premiered']
summary = data['summary']
print(f"{name} premiered on {premiered}.")
print(summary)
else:
print(f"Error: {response.status_code}")
NEED HELP?
🆘 Watch this first and then let me know in the comments below: • Help Me Help You
❤️❤️ SHOW SOME LOVE AND SUPPORT THE CHANNEL ❤️❤️
Click Join and Become a Channel Member Today!
Channel members can get preferential comment replies, early access to new content, members only live streams, and access to my private Discord.
❤️ / @tokyoedtech
LINKS
🗄️ GITHUB: https://github.com/wynand1004
💬 Follow me on Twitter: / tokyoedtech
📜 Subscribe to my Newsletter: http://eepurl.com/dKgM8k
📝 Check out my Blog: https://christianthompson.com
⬇️ Download Geany Editor: https://www.geany.org
LEARN MORE PYTHON
➡️Space Invaders: • Python Game Programming Tutorial: Space In...
➡️Snake Game: • Python Game Programming Tutorial: Snake Ga...
➡️Pong: • Python Game Programming Tutorial: Pong Par...
➡️Space War: • Python Game Programming Tutorial: SpaceWar 1
➡️Intro to Python (for Java Coders): • Intro to Python for Java Coders: Comments ...
➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle Graphics Tutorial: ...
LEARN MORE JAVA
➡️Basic Java for Beginners: • Basic Java 1&2: Comments and Printing
➡️Intro to AP Computer Science A: • AP Computer Science Unit 1: Primitive Types
#Python #Tutorial #API #JSON