-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
42 lines (31 loc) · 1.21 KB
/
helpers.py
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
# some helper functions will be defined here
import requests
# The URL to fetch dishes from
URL = "https://www.10bis.co.il/NextApi/GetRestaurantMenu?culture=en&uiCulture=en&restaurantId=19156&deliveryMethod=pickup"
# categories to extract
CATEGORIES_TO_EXTRACT = ["Pizzas", "Drinks", "Desserts"]
# internal function
def generate_dish_item(item):
dish_item = {}
dish_item["id"] = item["dishId"]
dish_item["name"] = item["dishName"]
dish_item["description"] = item["dishDescription"]
dish_item["price"] = item["dishPrice"]
return dish_item
# internal function
def generate_dishes_dict(dish_list):
dishes_dict = {}
for dish in dish_list:
dishes_dict[int(dish["dishId"])] = generate_dish_item(dish)
return dishes_dict
# the method to fetch and build the data in appropriate structure
def build_data():
# a GET request is sent to the URL
response = requests.get(URL)
data = {}
raw_json = response.json()
for category in raw_json["Data"]["categoriesList"]:
if category["categoryName"] in CATEGORIES_TO_EXTRACT:
dishes_dict = generate_dishes_dict(category["dishList"])
data[category["categoryName"].lower()] = dishes_dict
return data