APIs & Looping Patterns
Do Now
1) What is the URL to retrieve data on the bubblegum named “Burny”?
http://api.bubblegum.com/gum/d0g/show.json?APIKEY=b335
2) Request a list of all bubblegum flavors, and print each flavor’s name.
import requests
url = 'http://api.bubblegum.com/gum/d0g/show.json?APIKEY=b335'
response = requests.get(url)
data = response.json()
data.key()
print(type(data['flavors']))
for flavor in flavors:
print(flavor)
3) Retrieve the bubblegum named “Minty Fresh” and if it has a popularity of more than 100, print “Wow, that’s popular”
if data['popularity'] > 100:
print "Wow that's popular"
4) Using the same data as question 3, print each flavor that Minty Fresh has in it.
flavors = data['flavors']
for flavor in flavors:
print(flavor)
Homework
Switching to ipython notebook mode to review (some) HW5 problems: