-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopola_database.py
More file actions
86 lines (73 loc) · 2.77 KB
/
popola_database.py
File metadata and controls
86 lines (73 loc) · 2.77 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
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
85
86
import sqlite3
from datetime import datetime, timedelta
# Dati da inserire per i tavoli
tables = [
{
"capacity": 4 + (i % 3) * 2,
"status": "libero",
"assigned_to": None,
"turno": None,
"data": None,
"customer_name": None
}
for i in range(1, 21)
]
# Dati per i camerieri
waiters = [
{"name": "Waiter 1"},
{"name": "Waiter 2"},
{"name": "Waiter 3"},
{"name": "Waiter 4"}
]
# Dati per le pietanze
products = {
"antipasto": {"Bruschetta": (6.00, 5), "Garlic Bread": (4.50, 3), "Caprese Salad": (8.00, 7)},
"primo": {"Pizza Margherita": (8.00, 10), "Pasta Carbonara": (10.00, 15), "Seafood Risotto": (18.00, 20)},
"secondo": {"Grilled Steak": (15.00, 25)},
"contorno": {"Fries": (3.50, 5), "Salad": (4.50, 6), "Grilled Vegetables": (6.00, 8)},
"dolce": {"Ice Cream": (3.50, 5), "Cake": (4.00, 7), "Tiramisu": (5.00, 10)},
"bevanda": {"Water": (1.50, 0), "Coca Cola": (2.50, 0), "Wine": (5.00, 0), "Beer": (4.00, 0)},
}
# Ottieni la data di oggi e la data di domani
today = datetime.now().strftime("%Y-%m-%d")
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")
# Dati per le prenotazioni iniziali
reservations = [
("Francesca", 6, 1, today, "pranzo"),
("Paolo", 2, 2, today, "cena"),
("Marco", 8, 3, today, "cena"),
("Laura", 5, 1, tomorrow, "pranzo"),
("Giulia", 3, 4, tomorrow, "pranzo"),
("Alessandro", 7, 2, tomorrow, "cena"),
]
# Funzione per popolare il database
def popola_database():
conn = sqlite3.connect('ristorante1.db')
cursor = conn.cursor()
# Inserire i camerieri
for waiter in waiters:
cursor.execute("INSERT INTO Camerieri (nome) VALUES (?)", (waiter["name"],))
# Inserire i tavoli
for table in tables:
cursor.execute(
"INSERT INTO Tavoli (posti, stato, cameriere_id, turno, data, customer_name) VALUES (?, ?, ?, ?, ?, ?)",
(table["capacity"], table["status"], table["assigned_to"], table["turno"], table["data"], table["customer_name"])
)
# Inserire le pietanze
for category, items in products.items():
for name, (price, prep_time) in items.items():
cursor.execute(
"INSERT INTO Pietanze (nome, prezzo, categoria, tempo_preparazione) VALUES (?, ?, ?, ?)",
(name, price, category, prep_time)
)
# Inserire prenotazioni iniziali, se presenti
for reservation in reservations:
cursor.execute(
"INSERT INTO Prenotazioni (cliente_nome, tavolo_id, cameriere_id, data, turno) VALUES (?, ?, ?, ?, ?)",
reservation # Usa direttamente la tupla
)
conn.commit()
conn.close()
if __name__ == "__main__":
popola_database()
print("Database popolato con successo!")