How to Access Web APIs using Python Requests and JSON
Channel: TokyoEdtech
Date: 2021-05-24

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: https://www.youtube.com/watch?v=L6AwVuu6O3Y

❤️❤️ 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. 
❤️ https://www.youtube.com/channel/UC2vm-0XX5RkWCXWwtBZGOXg/join

LINKS
🗄️ GITHUB: https://github.com/wynand1004
💬 Follow me on Twitter: https://twitter.com/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: https://www.youtube.com/watch?v=QvtlEj_T55o&list=PLlEgNdBJEO-lqvqL5nNNZC6KoRdSrhQwK
➡️Snake Game: https://www.youtube.com/watch?v=BP7KMlbvtOo&list=PLlEgNdBJEO-n8k9SR49AshB9j7b5Iw7hZ 
➡️Pong: https://www.youtube.com/watch?v=LH8WgrUWG_I&list=PLlEgNdBJEO-kXk2PyBxhSmo84hsO3HAz2 
➡️Space War: https://www.youtube.com/watch?v=Ak1IDnP5IrI&list=PLlEgNdBJEO-muprNCDYiKLZ-Kc3-p8thS 
➡️Intro to Python (for Java Coders): https://www.youtube.com/watch?v=hIulVFh4S-k&list=PLlEgNdBJEO-n4c4QMmUVknHxfjDlvbY1l
➡️Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: https://www.youtube.com/watch?v=nUoJjHOlY24&list=PLlEgNdBJEO-kK78GXDVzytiZlJtCyiFyW 

LEARN MORE JAVA
➡️Basic Java for Beginners: https://www.youtube.com/watch?v=FxmQeC-3uuE&list=PLlEgNdBJEO-lCMWT4wd3VbZbv_swTd_eT 

➡️Intro to AP Computer Science A: https://www.youtube.com/watch?v=1g99HckBk8c&list=PLlEgNdBJEO-kaJjwvtMrBBrm6-i4w1TQG

#Python #Tutorial #API #JSON