-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
176 lines (143 loc) · 4.52 KB
/
main.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
from getpass import getpass
from utils import clear
import users
import menus
import films
import sales
DB = {
'user_types': ['admin', 'client'],
'users': [
{
'id': '1',
'name': 'Admin',
'email': '[email protected]',
'password': 'admin',
'type': 'admin'
},
{
'id': '2',
'name': 'Cliente',
'email': '[email protected]',
'password': 'client',
'type': 'client'
},
{
'id': '3',
'name': 'Cliente 2',
'email': '[email protected]',
'password': 'client',
'type': 'client'
}
],
'films': [
{
'id': '2',
'title': 'Filme B',
'description': 'Descrição do filme 2',
'duration': '120', # in minutes
'genre': ['Ação', 'Aventura'],
'room_number': '1',
'time': 'manhã', # 'manhã', 'tarde', 'noite'
'capacity': 100,
'price': 20.00,
},
{
'id': '1',
'title': 'Filme A',
'description': 'Descrição do filme 1',
'duration': '120', # in minutes
'genre': ['Ação', 'Aventura'],
'room_number': '1',
'time': 'manhã', # 'manhã', 'tarde', 'noite'
'capacity': 100,
'price': 20.00,
}
],
'sales': [
{
'id': '1',
'film_id': '1',
'user_id': '2'
},
{
'id': '2',
'film_id': '2',
'user_id': '3'
}
],
}
previous_menu = menus.MAIN_MENU
active_menu = menus.MAIN_MENU
user_logged = None
while True:
clear()
print('=' * 15, 'BEM VINDO AO CINE SERTÃO', '=' * 15)
if (user_logged):
print(f"\nOlá, {user_logged['name']}!")
print(f"\n* {active_menu['title']}")
valid_menu_options = []
for option in active_menu['options']:
if user_logged == None:
if (option['need_auth'] or len(option['roles'])):
continue
else:
if (option['need_no_auth'] or (len(option['roles']) and user_logged['type'] not in option['roles'])):
continue
valid_menu_options.append(option)
print(f"{len(valid_menu_options)}. {option['title']}")
menu_index = input("\nEscolha uma opção: ")
if (not menu_index.isdigit() or
int(menu_index) < 1 or
int(menu_index) > len(valid_menu_options)
):
getpass("Opção inválida.\n\nPressione Enter para continuar...")
continue
menu_option = valid_menu_options[int(menu_index) - 1]
print('')
if menu_option['code'] == 'films_menu':
active_menu = menus.FILM_MENU
continue
elif menu_option['code'] == 'users_menu':
active_menu = menus.USER_MENU
continue
elif menu_option['code'] == 'store_sale':
sales.store_sale(DB, user_logged)
elif menu_option['code'] == 'index_available_film':
films.index_available_film(DB)
elif menu_option['code'] == 'index_film':
films.index_film(DB)
elif menu_option['code'] == 'index_popular_film':
films.index_popular_film(DB)
elif menu_option['code'] == 'store_film':
films.store_film(DB)
elif menu_option['code'] == 'update_film':
films.update_film(DB)
elif menu_option['code'] == 'destroy_film':
films.destroy_film(DB)
elif menu_option['code'] == 'index_sale':
sales.print_sales(DB, user_logged)
elif menu_option['code'] == 'generate_sale_file':
sales.generate_sales_file(DB, user_logged)
elif menu_option['code'] == 'index_user':
users.index_user(DB)
elif menu_option['code'] == 'store_user':
users.store_user(DB, user_logged)
elif menu_option['code'] == 'update_user':
users.update_user(DB)
elif menu_option['code'] == 'destroy_user':
users.destroy_user(DB)
elif menu_option['code'] == 'login':
user_logged = users.login(DB)
elif menu_option['code'] == 'logout':
print(f"Até mais, {user_logged['name']}!")
user_logged = None
elif menu_option['code'] == 'back':
active_menu = previous_menu
continue
elif menu_option['code'] == 'exit':
name = 'usuário anônimo' if user_logged == None else user_logged['name']
print(f'Até mais, {name}!')
exit()
getpass("\nPressione Enter para continuar...")