-
Notifications
You must be signed in to change notification settings - Fork 0
/
animal.py
119 lines (96 loc) · 3.75 KB
/
animal.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import mysql.connector
conexao = mysql.connector.connect(
host='localhost',
user='root',
password='',
database='ong'
)
class Animal:
# praetros
def __init__(self,id_exame, nomeanimal, cor, idade, raca,porte,disponivel, deficiente, adotado,castrado,exames,local_encontro,data_encontro):
self.ide_exame = id_exame
self.nome = nomeanimal
self.idade = idade
self.raca = raca
self.porte_animal = porte
self.deficiente = deficiente
self.cor=cor
self.disponivel=disponivel
self.adotado=adotado
self.castrado=castrado
self.exames=exames
self.local_encontro=local_encontro
self.data_encontro=data_encontro
@classmethod
def cadastrar(self,id_exame, nomeanimal, cor, porte,raca, idade,disponivel, adotado, deficiente,castrado,exames,local_encontro,data_encontro):
connection = mysql.connector.connect(
host='localhost',
user='root',
password='',
database='ong'
)
cursor = connection.cursor()
comando = f'insert into cad_animal(id_exame, nome, cor, porte, raça, idade, disponivel, adotado, deficiente, castrado, quant_exames,local_encontro, data_encontro) values(%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s)'
data=(
f"{id_exame}",
f"{nomeanimal}",
f"{cor}",
f"{porte}",
f"{raca}",
f"{idade}",
f"{disponivel}",
f"{adotado}",
f"{deficiente}",
f"{castrado}",
f"{exames}",
f"{local_encontro}",
f"{data_encontro}"
)
cursor.execute(comando,data)
connection.commit()
print("\n===================== Cadastro concluído com sucesso =====================")
cursor.close()
connection.close()
@classmethod
def atualizardadosanimais(self,id_animal,id_exame, nomeanimal, cor, porte,raca, idade,disponivel, adotado, deficiente,castrado,exames,local_encontro,data_encontro):
connection=mysql.connector.connect(
host='localhost',
user='root',
password='',
database='ong'
)
cursor=connection.cursor()
comando=f"UPDATE cad_animal SET id_animal= '{id_animal}', id_exame='{id_exame}', nome='{nomeanimal}', cor='{cor}', porte='{porte}',raça='{raca}', idade='{idade}',disponivel='{disponivel}', adotado='{adotado}', deficiente='{deficiente}',castrado='{castrado}', quant_exames='{exames}',local_encontro='{local_encontro}',data_encontro='{data_encontro}' where id_animal='{id_animal}';"
cursor.execute(comando)
connection.commit()
cursor.close()
connection.close()
@classmethod
def consulta_animal(self,id_animal):
connection=mysql.connector.connect(
host='localhost',
user='root',
password='',
database='ong'
)
cursor=connection.cursor()
comando=f'select id_animal, id_exame, nome, cor, porte, raça, idade, disponivel, adotado, deficiente, castrado, quant_exames,local_encontro, data_encontro from cad_animal where id_animal="{id_animal}" '
cursor.execute(comando)
resultado=cursor.fetchall()
print(resultado)
cursor.close()
connection.close()
@classmethod
def deletar_aninal(self,id_animal):
connection=mysql.connector.connect(
host='localhost',
user='root',
password='',
database='ong'
)
cursor=connection.cursor()
comando=f'delete from cad_animal where id_animal= "{id_animal}"'
cursor.execute(comando)
connection.commit()
cursor.close()
connection.close()