Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- class Ingredient:
- def __init__(self, name, measurement):
- self.name = name
- self.measurement = measurement
- def __str__(self):
- if (self.measurement is None):
- return self.name
- return self.name + ", " + self.measurement
- url = "https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita"
- response = requests.get(url)
- data = response.json()
- cocktails = data["drinks"]
- for cocktail in cocktails:
- print(cocktail["strDrink"])
- ingredients = []
- x = 1
- while (True):
- strIngredient = "strIngredient" + str(x)
- strMeasure = "strMeasure" + str(x)
- name = cocktail[strIngredient]
- measurement = cocktail[strMeasure]
- if (name is None):
- break
- else:
- ingredients.append(Ingredient(name, measurement))
- x += 1
- print(' '.join(map(str, ingredients)))
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement