-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebscraper.py
More file actions
51 lines (39 loc) · 1.5 KB
/
webscraper.py
File metadata and controls
51 lines (39 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import requests
import json
#Put drink name here
drinkName = "whiskey sour"
response = requests.get(f'https://www.thecocktaildb.com/api/json/v1/1/search.php?s={drinkName}')
drinkObject = response.json()
drink = drinkObject["drinks"][0]
ingInfo = []
for ingredient in range(15):
ingKey = f'strIngredient{str(ingredient+1)}'
measureKey = f'strMeasure{str(ingredient+1)}'
if drink[ingKey] and drink[measureKey]:
ingInfo.append({
"ingredient": drink[ingKey],
"measurement": drink[measureKey]
})
returnedDrink ={
"Name": drink["strDrink"],
"Instructions": drink["strInstructions"],
"Category": drink["strCategory"],
"Ingredients": ingInfo
}
# print(returnedDrink)
start = f'This evening try out a {returnedDrink["Name"]} coming from the wonderful family of {returnedDrink["Category"]} drinks. All you need is '
test = ""
for ingObject in returnedDrink["Ingredients"]:
Idontknowwhattonamevariablesanymore = f'{ingObject["measurement"]} of {ingObject["ingredient"]}, '
test = test+Idontknowwhattonamevariablesanymore
end = f' and then {returnedDrink["Instructions"]}'
print(start+test+end)
# class drinkAPI():
# def __init__(self, drinkName):
# super().__init__()
# self.drinkInfo = {}
# def requestData(self, drinkName):
# response = requests.get(f'https://www.thecocktaildb.com/api/json/v1/1/search.php?s={drinkName}')
# drinkObject = response.json()
# return drinkObject
# def parseDrinkInformation(self)