-
Notifications
You must be signed in to change notification settings - Fork 0
/
petStore.py
42 lines (32 loc) · 1020 Bytes
/
petStore.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
from pet import Pet
import mysql.connector
class PetStore:
def __init__(self, pet_list=None) -> None:
if pet_list is None:
pet_list = []
self.petList = pet_list
def add_pet(self):
p1 = Pet()
print("Please name your pet.py")
p1.name = input()
print("What type of pet?")
p1.type = input()
print("Please type in the age of your pet.py")
p1.age = input()
self.petList.append(p1)
def print_pet_info(self):
for pet in self.petList:
print(pet.getInfo())
def read_from_database(self):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
password="password",
database="petstore"
)
cursor = mydb.cursor()
cursor.execute("SELECT * FROM pets")
results = cursor.fetchall()
for result in results:
pet = Pet(result[1], result[2], result[3])
self.petList.append(pet)