-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpizzaproducer.py
84 lines (78 loc) · 2.49 KB
/
pizzaproducer.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import random
import time
from faker.providers import BaseProvider
# Adding a PizzaProvider with 3 methods:
# * pizza_name to retrieve the name of the basic pizza,
# * pizza_topping for additional toppings
# * pizza_shop to retrieve one of the shops available
class PizzaProvider(BaseProvider):
def pizza_name(self):
valid_pizza_names = [
"Margherita",
"Marinara",
"Diavola",
"Mari & Monti",
"Salami",
"Peperoni",
]
return random.choice(valid_pizza_names)
def pizza_topping(self):
available_pizza_toppings = [
"🍅 tomato",
"🧀 blue cheese",
"🥚 egg",
"🫑 green peppers",
"🌶️ hot pepper",
"🥓 bacon",
"🫒 olives",
"🧄 garlic",
"🐟 tuna",
"🧅 onion",
"🍍 pineapple",
"🍓 strawberry",
"🍌 banana",
]
return random.choice(available_pizza_toppings)
def pizza_shop(self):
pizza_shops = [
"Marios Pizza",
"Luigis Pizza",
"Circular Pi Pizzeria",
"Ill Make You a Pizza You Can" "t Refuse",
"Mammamia Pizza",
"Its-a me! Mario Pizza!",
]
return random.choice(pizza_shops)
def produce_msg(
self,
FakerInstance,
ordercount=1,
max_pizzas_in_order=5,
max_toppings_in_pizza=3,
):
shop = FakerInstance.pizza_shop()
# Each Order can have 1-10 pizzas in it
pizzas = []
for pizza in range(random.randint(1, max_pizzas_in_order)):
# Each Pizza can have 0-5 additional toppings on it
toppings = []
for topping in range(random.randint(0, max_toppings_in_pizza)):
toppings.append(FakerInstance.pizza_topping())
pizzas.append(
{
"pizzaName": FakerInstance.pizza_name(),
"additionalToppings": toppings,
}
)
# message composition
message = {
"id": ordercount,
"shop": shop,
"name": FakerInstance.unique.name(),
"phoneNumber": FakerInstance.unique.phone_number(),
"address": FakerInstance.address(),
"pizzas": pizzas,
"timestamp": int(time.time() * 1000),
}
key = {"shop": shop}
return message, key