-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagement.py
99 lines (87 loc) · 2.97 KB
/
management.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
import json
from hotels import *
import os
class Management():
AGREGAR_HOTEL = 1
CONSULTAR_HOTEL = 2
CONSULTAR = 3
SALIR = 0
def __init__(self):
self._hoteles = []
self.recuperar_hoteles('hoteles.json')
def __del__(self):
self.almacenar_hoteles('hoteles.json')
@property
def hoteles(self):
return self._hoteles
@hoteles.setter
def hoteles(self, valor):
self._hoteles = valor
@hoteles.deleter
def hoteles(self):
del self._hoteles
def recuperar_hoteles(self, ruta):
with open(ruta, 'r') as archivo:
datahoteles = json.load(archivo)
for hotel in datahoteles['hoteles']:
self.hoteles.append(Hotels_Encoder.desde_json(hotel))
def almacenar_hoteles(self, ruta):
with open(ruta, 'w') as archivo:
json.dump({'hoteles':self.hoteles}, archivo, cls=Hotels_Encoder, indent=4)
def agregarHotel(self):
os.system('cls')
print(' Agregar Hotel')
nombre = input('nombre: ')
direccion = input('direccion: ')
telefono = input('telefono: ')
habitaciones = int(input('Habitaciones disponibles: '))
nroReservas = int(input('numero de reservas: '))
self.hoteles.append(Hotels(nombre, direccion, telefono, habitaciones, nroReservas))
def consultar_hoteles(self):
os.system('cls')
print(' Consultar Hoteles')
if len(self.hoteles) == 0:
print('No hay hoteles en la base de datos')
else:
for hotel in self.hoteles:
print(f'''
{hotel}''')
print('-'*50)
def consultar_hotel(self):
os.system('cls')
print(' Consultar Hotel')
nombre = input('nombre: ')
for hotel in self.hoteles:
if hotel.nombre == nombre:
print(hotel)
break
else:
print('Hotel no encontrado')
def menu(self):
continuar = True
while continuar:
os.system('cls')
print(f'''
{Management.AGREGAR_HOTEL}) Agregar Hotel
{Management.CONSULTAR_HOTEL}) Consultar hotel
{Management.CONSULTAR}) Consultar Hoteles
{Management.SALIR}) Salir
''')
opc = input('Seleccione una opcion: ')
try:
opc = int(opc)
except:
opc = -1
if opc == Management.AGREGAR_HOTEL:
self.agregarHotel()
elif opc == Management.CONSULTAR_HOTEL:
self.consultar_hotel()
elif opc == Management.CONSULTAR:
self.consultar_hoteles()
elif opc == Management.SALIR:
continuar = False
else:
os.system('cls')
print('Opcion no valida')
input('Presiona enter para continuar')
input('Presiona Enter para salir')