-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
800 lines (728 loc) · 42.5 KB
/
Copy pathproject.py
File metadata and controls
800 lines (728 loc) · 42.5 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
from sys import exit
from csv import DictReader, DictWriter
from termcolor import cprint
login_password = "1234"
hotel_room_limit = 10
empty_rooms = []
hotel_guests = []
def main():
try:
print("\nWelcome !\n")
for login_tries in range(3):
if login(input("Please enter the password : ").strip(),login_password):
break
elif login_tries == 2:
cprint("\nToo many incorrect tries, access denied\n","red")
exit()
else:
cprint(f"\nincorrect password, you have {3-(login_tries+1)} tries left !\n","red")
cprint("\naccess granted !","green")
while True:
handle_empty_rooms()
handle_hotel_guests()
choice()
except KeyboardInterrupt:
print()
cprint("\nThe program force quit\n","red")
exit()
def choice():
if len(empty_rooms) == 0:
try:
for function_tries in range(3):
print("\nPlease choose a function:\n check guest access: press number 2\n search for guest: press number 3\n remove guest: press number 4\n logout: press number 5\n")
choice = input("Function number: ")
try:
choice = int(choice.strip())
except ValueError:
if function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 2 || 3 || 4 || 5 |","red" )
else:
if choice in [2,3,4,5]:
break
elif function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
if choice not in [2,3,4,5]:
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 2 || 3 || 4 || 5 |","red" )
match choice:
case 2:
for check_access_tries in range(3):
name = input("\nWhose access would you like to check : ")
service = input("Wich service : ")
if check_guest_access("hotel_guests_list.csv",name,service)[0] == "error":
cprint(f"{check_guest_access('hotel_guests_list.csv',name,service)[1]}, you have {3-(check_access_tries+1)} tries left","red")
else:
if check_guest_access("hotel_guests_list.csv",name,service)[0] == "denied":
cprint(check_guest_access('hotel_guests_list.csv',name,service)[1],"red")
break
else:
cprint(check_guest_access('hotel_guests_list.csv',name,service)[1],"green")
break
case 3:
for search_client_tries in range(3):
guest = input("\nWhose information would you like ? ")
if search_for_client("hotel_guests_list.csv",guest)[0] == "error":
cprint(f"{search_for_client('hotel_guests_list.csv',guest)[1]}, you have {3-(search_client_tries+1)} tries left","red")
else:
print(search_for_client("hotel_guests_list.csv",guest)[1])
break
case 4:
for remove_tries in range(3):
hotel_guests_name = []
for h_g in hotel_guests:
hotel_guests_name.append(h_g["name"])
guest_name = input("\nThe guest name who you want to remove : ").strip().lower().title()
if guest_name in hotel_guests_name:
for guest in hotel_guests:
if guest["name"] == guest_name:
manage_room("add",int(guest["room"]))
break
remove_guest(guest_name)
cprint(f"\nGuest {guest_name} is succesfully removed","green")
break
else:
cprint(f"\nInvalid guest name : {guest_name}, {guest_name} is not a hotel guest, you have {3-(remove_tries+1)} tries left","red")
case 5:
for logout_tries in range(3):
logout_choice = input("\nDo you want to logout: 'yes'/'no' ").strip().lower()
if logout_choice == "yes":
logout()
elif logout_choice == "no":
break
else:
cprint(f"\nInvalid response {logout_choice}, please respond with 'yes' or 'no', you have {3-(logout_tries+1)} tries left","red")
except KeyboardInterrupt:
print()
for exit_tries in range(3):
exit_choice = input("\nDo you want to force quit (not recommened) ? yes/no : ").strip().lower()
if exit_choice == "yes":
cprint("\nThe program force quit\n","red")
exit()
elif exit_choice == "no":
break
else:
cprint(f"\nInvalid response : {exit_choice}, please respond with 'yes' or 'no', you have {3-(exit_tries+1)} tries left","red")
elif len(hotel_guests) == 0:
try:
for function_tries in range(3):
print("\nPlease choose a function:\n add guest: press number 1\n logout: press number 5\n")
choice = input("Function number: ")
try:
choice = int(choice.strip())
except ValueError:
if function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 1 || 5 |","red" )
else:
if choice in [1,5]:
break
elif function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
if choice not in [1,5]:
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 1 || 5 |","red" )
match choice:
case 1:
last_correct_data = None
print("\nHere are the empty rooms : ",end="")
for e_r in empty_rooms:
print(f"| {e_r} |",end="")
print()
for room_tries in range(3):
room = input("\nWhich one would you like ? ")
if check_room("empty_rooms_list.txt",room) == "correct":
last_correct_data = "room"
break
else:
cprint(f"\nIncorrect room number : {room}, you have {3-(room_tries+1)} tries left, please choose one of these rooms : ","red",end="")
for e_r in empty_rooms:
print(f"| {e_r} |",end="")
print()
if last_correct_data == "room":
for name_tries in range(3):
name = input("\nAt which name would you like to get the room ? ")
if check_name("hotel_guests_list.csv",name) == "correct":
last_correct_data = "name"
break
else:
cprint(f"\nInvalid name : {name}, you have {3-(name_tries+1)} tries left","red")
if last_correct_data == "name":
for package_tries in range(3):
package = input("\nWhich package would you like ? ")
if check_package(package) == "correct":
last_correct_data = "package"
break
else:
cprint(f"\nIncorrect package : {package}, you have {3-(package_tries+1)} tries left, please choose one of these packages : 'normal', 'premium', 'luxury'","red")
if last_correct_data == "package":
for night_tries in range(3):
night = input("\nHow many nights would you like to stay ? ")
if check_night(night) == "correct":
last_correct_data = "night"
break
else:
cprint(f"\nIncorrect number of nights : {night}, you have {3-(night_tries+1)} tries left, please choose a number greater than 0","red")
if last_correct_data == "night":
for adult_tries in range(3):
adult = input("\nHow many adult would like to stay ? ")
if check_adult(adult) == "correct":
last_correct_data = "adult"
break
else:
cprint(f"\nIncorrect number of adults: {adult}, you have {3-(adult_tries+1)} tries left, please choose a number greater than 0","red")
if last_correct_data == "adult":
for kid_tries in range(3):
kid = input("\nHow many kids would like to stay ? ")
if check_kid(kid) == "correct":
last_correct_data = "kid"
break
else:
cprint(f"\nIncorrect number of kids : {kid}, you have {3-(kid_tries+1)} tries left, please choose a number greater or equal to 0","red")
if last_correct_data == "kid":
guest_data = make_guest_data(name,adult,kid,package,night,room)
cprint(f"\nThats will be ${get_price(adult,kid,package,night):,}\n","yellow",end="")
for pay_tries in range(3):
response = input("\nDid the guest paid ? yes/no ").strip().lower()
if response == "yes":
manage_room("remove",guest_data["room"])
add_guest(guest_data)
cprint(f"\nGuest {guest_data['name']} is succesfully added","green")
break
elif response == "no":
cprint(f"\nSorry but without paying the hotel can't provide any service","red")
break
else:
cprint(f"\nInvalid input : {response}, you have {3-(pay_tries+1)} tries left, please respond with yes or no","red")
case 5:
for logout_tries in range(3):
logout_choice = input("\nDo you want to logout: 'yes'/'no' ").strip().lower()
if logout_choice == "yes":
logout()
elif logout_choice == "no":
break
else:
cprint(f"\nInvalid response {logout_choice}, please respond with 'yes' or 'no', you have {3-(logout_tries+1)} tries left","red")
except KeyboardInterrupt:
print()
for exit_tries in range(3):
exit_choice = input("\nDo you want to force quit (not recommened) ? yes/no : ").strip().lower()
if exit_choice == "yes":
cprint("\nThe program force quit\n","red")
exit()
elif exit_choice == "no":
break
else:
cprint(f"\nInvalid response : {exit_choice}, please respond with 'yes' or 'no', you have {3-(exit_tries+1)} tries left","red")
else:
try:
for function_tries in range(3):
print("\nPlease choose a function:\n add guest: press number 1\n check guest access: press number 2\n search for guest: press number 3\n remove guest: press number 4\n logout: press number 5\n")
choice = input("Function number: ")
try:
choice = int(choice.strip())
except ValueError:
if function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 1 || 2 || 3 || 4 || 5 |","red" )
else:
if choice in [1,2,3,4,5]:
break
elif function_tries == 2:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
if choice not in [1,2,3,4,5]:
cprint(f"\nincorrect function number : {choice}, you have {3-(function_tries+1)} tries left, please choose one of these : | 1 || 2 || 3 || 4 || 5 |","red" )
match choice:
case 1:
last_correct_data = None
print("\nHere are the empty rooms : ",end="")
for e_r in empty_rooms:
print(f"| {e_r} |",end="")
print()
for room_tries in range(3):
room = input("\nWhich one would you like ? ")
if check_room("empty_rooms_list.txt",room) == "correct":
last_correct_data = "room"
break
else:
cprint(f"\nIncorrect room number : {room}, you have {3-(room_tries+1)} tries left, please choose one of these rooms : ","red",end="")
for e_r in empty_rooms:
print(f"| {e_r} |",end="")
print()
if last_correct_data == "room":
for name_tries in range(3):
name = input("\nAt which name would you like to get the room ? ")
if check_name("hotel_guests_list.csv",name) == "correct":
last_correct_data = "name"
break
else:
cprint(f"\nInvalid name : {name}, you have {3-(name_tries+1)} tries left","red")
if last_correct_data == "name":
for package_tries in range(3):
package = input("\nWhich package would you like ? ")
if check_package(package) == "correct":
last_correct_data = "package"
break
else:
cprint(f"\nIncorrect package : {package}, you have {3-(package_tries+1)} tries left, please choose one of these packages : 'normal', 'premium', 'luxury'","red")
if last_correct_data == "package":
for night_tries in range(3):
night = input("\nHow many nights would you like to stay ? ")
if check_night(night) == "correct":
last_correct_data = "night"
break
else:
cprint(f"\nIncorrect number of nights : {night}, you have {3-(night_tries+1)} tries left, please choose a number greater than 0","red")
if last_correct_data == "night":
for adult_tries in range(3):
adult = input("\nHow many adult would like to stay ? ")
if check_adult(adult) == "correct":
last_correct_data = "adult"
break
else:
cprint(f"\nIncorrect number of adults: {adult}, you have {3-(adult_tries+1)} tries left, please choose a number greater than 0","red")
if last_correct_data == "adult":
for kid_tries in range(3):
kid = input("\nHow many kids would like to stay ? ")
if check_kid(kid) == "correct":
last_correct_data = "kid"
break
else:
cprint(f"\nIncorrect number of kids : {kid}, you have {3-(kid_tries+1)} tries left, please choose a number greater or equal to 0","red")
if last_correct_data == "kid":
guest_data = make_guest_data(name,adult,kid,package,night,room)
cprint(f"\nThats will be ${get_price(adult,kid,package,night):,}\n","yellow",end="")
for pay_tries in range(3):
response = input("\nDid the guest paid ? yes/no ").strip().lower()
if response == "yes":
manage_room("remove",guest_data["room"])
add_guest(guest_data)
cprint(f"\nGuest {guest_data['name']} is succesfully added","green")
break
elif response == "no":
cprint(f"\nSorry but without paying the hotel can't provide any service","red")
break
else:
cprint(f"\nInvalid input : {response}, you have {3-(pay_tries+1)} tries left, please respond with yes or no","red")
case 2:
for check_access_tries in range(3):
name = input("\nWhose access would you like to check : ")
service = input("Wich service : ")
if check_guest_access("hotel_guests_list.csv",name,service)[0] == "error":
cprint(f"{check_guest_access('hotel_guests_list.csv',name,service)[1]}, you have {3-(check_access_tries+1)} tries left","red")
else:
if check_guest_access("hotel_guests_list.csv",name,service)[0] == "denied":
cprint(check_guest_access('hotel_guests_list.csv',name,service)[1],"red")
break
else:
cprint(check_guest_access('hotel_guests_list.csv',name,service)[1],"green")
break
case 3:
for search_client_tries in range(3):
guest = input("\nWhose information would you like ? ")
if search_for_client("hotel_guests_list.csv",guest)[0] == "error":
cprint(f"{search_for_client('hotel_guests_list.csv',guest)[1]}, you have {3-(search_client_tries+1)} tries left","red")
else:
print(search_for_client("hotel_guests_list.csv",guest)[1])
break
case 4:
for remove_tries in range(3):
hotel_guests_name = []
for h_g in hotel_guests:
hotel_guests_name.append(h_g["name"])
guest_name = input("\nThe guest name who you want to remove : ").strip().lower().title()
if guest_name in hotel_guests_name:
for guest in hotel_guests:
if guest["name"] == guest_name:
manage_room("add",int(guest["room"]))
break
remove_guest(guest_name)
cprint(f"\nGuest {guest_name} is succesfully removed","green")
break
else:
cprint(f"\nInvalid guest name : {guest_name}, {guest_name} is not a hotel guest, you have {3-(remove_tries+1)} tries left","red")
case 5:
for logout_tries in range(3):
logout_choice = input("\nDo you want to logout: 'yes'/'no' ").strip().lower()
if logout_choice == "yes":
logout()
elif logout_choice == "no":
break
else:
cprint(f"\nInvalid response {logout_choice}, please respond with 'yes' or 'no', you have {3-(logout_tries+1)} tries left","red")
except KeyboardInterrupt:
print()
for exit_tries in range(3):
exit_choice = input("\nDo you want to force quit (not recommened) ? yes/no : ").strip().lower()
if exit_choice == "yes":
cprint("\nThe program force quit\n","red")
exit()
elif exit_choice == "no":
break
else:
cprint(f"\nInvalid response : {exit_choice}, please respond with 'yes' or 'no', you have {3-(exit_tries+1)} tries left","red")
def handle_empty_rooms():
global empty_rooms
empty_rooms = []
empty_rooms_set = set()
with open("empty_rooms_list.txt") as file:
for line in file.readlines():
if line.rstrip().isdecimal() == True:
empty_rooms_set.add(int(line.rstrip()))
for room in empty_rooms_set:
empty_rooms.append(room)
with open("empty_rooms_list.txt","w") as file:
for e_r in sorted(empty_rooms):
file.write(f"{str(e_r)}\n")
empty_rooms = sorted(empty_rooms)
def handle_hotel_guests():
global hotel_guests
hotel_guests = []
hotel_guests_name = []
hotel_guests_room = []
with open("hotel_guests_list.csv") as file:
for guest in DictReader(file):
try:
if guest not in hotel_guests and guest["name"].istitle() and guest["adult"].isdecimal() and (int(guest["adult"]) >= 1) and guest["kid"].isdecimal() and (int(guest["kid"]) >= 0) and guest["package"] in ["normal","premium","luxury"] and guest["night"].isdecimal() and (int(guest["night"]) >= 1) and guest["room"].isdecimal() and (int(guest["room"]) not in empty_rooms):
hotel_guests.append(guest)
except AttributeError:
pass
for append_guest_data in hotel_guests:
hotel_guests_name.append(append_guest_data["name"])
hotel_guests_room.append(append_guest_data["room"])
for name in set(hotel_guests_name):
if hotel_guests_name.count(name) > 1:
cprint(f"\nThere are multiple guests with the same name : {name}, please choose which one is the CORRECT !","red")
guest_with_number = []
number_of_the_guest = 0
for hg in hotel_guests:
if hg["name"] == name:
number_of_the_guest += 1
print(f"Number : {number_of_the_guest} Name : {hg['name']}, Adult : {hg['adult']}, Kid : {hg['kid']}, Package : {hg['package']}. Night : {hg['night']}, Room : {hg['room']}")
guest_with_number.append({"number_of_the_guest" : number_of_the_guest, "guest" : hg})
for name_tries in range(3):
try:
correct_guest_number = int(input("\nThe number of the CORRECT guest : ").strip())
except ValueError :
if name_tries != 2:
cprint(f"\nInvalid number : Not a Number, please choose a number displayed after the 'Number' text, you have {3-(name_tries+1)} tries left","red")
for gwn in guest_with_number:
print(f"Number : {gwn['number_of_the_guest']} Name : {gwn['guest']['name']}, Adult : {gwn['guest']['adult']}, Kid : {gwn['guest']['kid']}, Package : {gwn['guest']['package']}. Night : {gwn['guest']['night']}, Room : {gwn['guest']['room']}")
else:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
else:
if ((correct_guest_number < 1) or (correct_guest_number > number_of_the_guest)) and (name_tries == 2):
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
elif ((correct_guest_number < 1) or (correct_guest_number > number_of_the_guest)):
cprint(f"\nInvalid number : {correct_guest_number}, please choose a number displayed after the 'Number' text, you have {3-(name_tries+1)} tries left","red")
for gwn in guest_with_number:
print(f"Number : {gwn['number_of_the_guest']} Name : {gwn['guest']['name']}, Adult : {gwn['guest']['adult']}, Kid : {gwn['guest']['kid']}, Package : {gwn['guest']['package']}. Night : {gwn['guest']['night']}, Room : {gwn['guest']['room']}")
else:
for g_w_n in guest_with_number:
if g_w_n["number_of_the_guest"] == correct_guest_number:
correct_guest = g_w_n["guest"]
break
break
while hotel_guests_name.count(name) > 1:
for h_g_index in range(len(hotel_guests)):
if (hotel_guests[h_g_index]["name"] == name) and (hotel_guests[h_g_index] != correct_guest):
del hotel_guests[h_g_index]
break
for hgn_index in range(len(hotel_guests_name)):
if (hotel_guests_name[hgn_index] == name) and (hotel_guests_room[hgn_index] != correct_guest["room"]):
del hotel_guests_name[hgn_index]
del hotel_guests_room[hgn_index]
break
elif (hotel_guests_name[hgn_index] == name) and (hotel_guests_room[hgn_index] == correct_guest["room"]) and (hotel_guests_room.count(correct_guest["room"]) > 1):
del hotel_guests_name[hgn_index]
del hotel_guests_room[hgn_index]
break
for room in set(hotel_guests_room):
if hotel_guests_room.count(room) > 1:
cprint(f"\nThere are multiple guests with the same room : {room}, please choose which one is the CORRECT !","red")
guest_with_number = []
number_of_the_guest = 0
for h_guest in hotel_guests:
if h_guest["room"] == room:
number_of_the_guest += 1
print(f"Number : {number_of_the_guest} Name : {h_guest['name']}, Adult : {h_guest['adult']}, Kid : {h_guest['kid']}, Package : {h_guest['package']}. Night : {h_guest['night']}, Room : {h_guest['room']}")
guest_with_number.append({"number_of_the_guest" : number_of_the_guest, "guest" : h_guest})
for room_tries in range(3):
try:
correct_room_number = int(input("\nThe number of the CORRECT guest : ").strip())
except ValueError :
if room_tries != 2:
cprint(f"\nInvalid number : Not a Number, please choose a number displayed after the 'Number' text, you have {3-(room_tries+1)} tries left","red")
for gwn in guest_with_number:
print(f"Number : {gwn['number_of_the_guest']} Name : {gwn['guest']['name']}, Adult : {gwn['guest']['adult']}, Kid : {gwn['guest']['kid']}, Package : {gwn['guest']['package']}. Night : {gwn['guest']['night']}, Room : {gwn['guest']['room']}")
else:
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
else:
if ((correct_room_number < 1) or (correct_room_number > number_of_the_guest)) and (room_tries == 2):
cprint(f"\nInvalid number : {correct_room_number}, please choose a number displayed after the 'Number' text, you have {3-(room_tries+1)} tries left","red")
for gwn in guest_with_number:
print(f"Number : {gwn['number_of_the_guest']} Name : {gwn['guest']['name']}, Adult : {gwn['guest']['adult']}, Kid : {gwn['guest']['kid']}, Package : {gwn['guest']['package']}. Night : {gwn['guest']['night']}, Room : {gwn['guest']['room']}")
elif ((correct_room_number < 1) or (correct_room_number > number_of_the_guest)):
cprint("\nToo many incorrect tries, the program closes itself\n","red")
exit()
else:
for g_w_n in guest_with_number:
if g_w_n["number_of_the_guest"] == correct_room_number:
correct_guest = g_w_n["guest"]
break
break
while hotel_guests_room.count(room) > 1:
for hg_index in range(len(hotel_guests)):
if (hotel_guests[hg_index]["room"] == room) and (hotel_guests[hg_index] != correct_guest):
del hotel_guests[hg_index]
break
for hgr_index in range(len(hotel_guests_room)):
if (hotel_guests_room[hgr_index] == room) and (hotel_guests_name[hgr_index] != correct_guest["name"]):
del hotel_guests_room[hgr_index]
del hotel_guests_name[hgr_index]
break
with open("hotel_guests_list.csv","w") as file:
writer = DictWriter(file, fieldnames=["name","adult","kid","package","night","room"])
writer.writeheader()
for write_guest in sorted(hotel_guests, key=lambda guest: guest["name"]):
writer.writerow(write_guest)
def login(password_entered,actual_password):
if password_entered == actual_password:
return True
def check_room(rooms_list,room):
empty_rooms_set = set()
try:
rooms_list = rooms_list.strip()
except AttributeError:
pass
else:
with open(rooms_list) as file:
for line in file.readlines():
if line.rstrip().isdecimal() == True:
empty_rooms_set.add(int(line.rstrip()))
try:
if int(room.strip()) in empty_rooms_set:
return "correct"
except (ValueError, AttributeError, TypeError):
pass
def check_name(guests_list,name):
hotel_guests=[]
try:
guests_list = guests_list.strip()
name = name.strip().lower().title()
except AttributeError:
pass
else:
with open(guests_list) as file:
for guest in DictReader(file):
try:
if guest not in hotel_guests and guest["name"].istitle() and guest["adult"].isdecimal() and (int(guest["adult"]) >= 1) and guest["kid"].isdecimal() and (int(guest["kid"]) >= 0) and guest["package"] in ["normal","premium","luxury"] and guest["night"].isdecimal() and (int(guest["night"]) >= 1) and guest["room"].isdecimal():
hotel_guests.append(guest)
except AttributeError:
pass
hotel_guest_names=[]
for guest in hotel_guests:
hotel_guest_names.append(guest["name"])
if name not in hotel_guest_names and name.istitle():
return "correct"
def check_package(package):
try:
if package.strip().lower() in ["normal","premium","luxury"]:
return "correct"
except AttributeError:
pass
def check_night(night):
try:
if int(night.strip()) > 0:
return "correct"
except (ValueError, AttributeError):
pass
def check_adult(adult):
try:
if int(adult.strip()) > 0:
return "correct"
except (ValueError, AttributeError):
pass
def check_kid(kid):
try:
if int(kid.strip()) >= 0:
return "correct"
except (ValueError, AttributeError):
pass
def make_guest_data(name,adult,kid,package,night,room):
try:
return {"name": name.strip().lower().title(), "adult": int(adult.strip()), "kid": int(kid.strip()), "package": package.strip().lower(), "night": int(night.strip()), "room": int(room.strip())}
except (ValueError, AttributeError):
pass
def get_price(adult,kid,package,night):
try:
match package.strip().lower():
case "normal":
return (int(adult.strip())*300 + int(kid.strip())*150)*int(night.strip())
case "premium":
return (int(adult.strip())*600 + int(kid.strip())*300)*int(night.strip())
case "luxury":
return (int(adult.strip())*900 + int(kid.strip())*450)*int(night.strip())
except (ValueError, AttributeError):
pass
def manage_room(mode,room):
global empty_rooms
try:
mode = mode.strip().lower()
except AttributeError:
pass
else:
if mode == "remove":
for index in range(len(empty_rooms)):
if empty_rooms[index] == room:
del empty_rooms[index]
break
with open("empty_rooms_list.txt","w") as file:
for room in sorted(empty_rooms):
file.write(f"{str(room)}\n")
elif mode == "add":
empty_rooms.append(room)
with open("empty_rooms_list.txt","w") as file:
for e_r in sorted(empty_rooms):
file.write(f"{str(e_r)}\n")
def add_guest(guest):
global hotel_guests
hotel_guests.append(guest)
with open("hotel_guests_list.csv","w") as file:
writer = DictWriter(file, fieldnames=["name","adult","kid","package","night","room"])
writer.writeheader()
for h_g in sorted(hotel_guests, key=lambda guest: guest["name"]):
writer.writerow(h_g)
def check_guest_access(guests_list,name,service):
premium = ["pool","gym"]
luxury = ["pool","gym","dining","massage","sauna"]
hotel_guests_name = []
hotel_guests = []
try:
guests_list = guests_list.strip()
except AttributeError:
return "error",f"Invalid type for guests_list : {str(type(guests_list)).split(' ')[1].rstrip('>')}, guests_list must be string"
else:
with open(guests_list) as file:
for guest in DictReader(file):
try:
if guest not in hotel_guests and guest["name"].istitle() and guest["adult"].isdecimal() and (int(guest["adult"]) >= 1) and guest["kid"].isdecimal() and (int(guest["kid"]) >= 0) and guest["package"] in ["normal","premium","luxury"] and guest["night"].isdecimal() and (int(guest["night"]) >= 1) and guest["room"].isdecimal():
hotel_guests.append(guest)
except AttributeError:
pass
for h_g in hotel_guests:
hotel_guests_name.append(h_g["name"])
try:
name = name.strip().lower().title()
service = service.strip().lower()
except AttributeError:
if type(name) != str and type(service) != str:
return "error",f"Invalid type for name and service : {str(type(name)).split(' ')[1].rstrip('>')} and {str(type(service)).split(' ')[1].rstrip('>')}, name and service must be string"
elif type(name) == str and type(service) != str:
if name in hotel_guests_name:
return "error",f"Invalid type for service : {str(type(service)).split(' ')[1].rstrip('>')}, service must be string"
else:
return "error",f"Invalid name : {name}, {name} not a hotel guest and invalid type for service {str(type(service)).split(' ')[1].rstrip('>')}, service must be string"
else:
if service in luxury:
return "error",f"Invalid type for name : {str(type(name)).split(' ')[1].rstrip('>')}, name must be string"
else:
return "error",f"Invalid service : {service}, {service} not one of the hotel services and invalid type for name {str(type(name)).split(' ')[1].rstrip('>')}, name must be string"
else:
if (name in hotel_guests_name) and (service in luxury):
for hg in hotel_guests:
if hg["name"] == name:
match hg["package"]:
case "normal":
return "denied",f"\naccess denied, normal package which {name} bought dont include any service"
case "premium":
if service in premium:
return "granted","\naccess granted"
else:
return "denied",f"\naccess denied, premium package which {name} bought dont include {service}"
case "luxury":
return "granted","\naccess granted"
else:
if (name not in hotel_guests_name) and (service in luxury):
if name == "":
return "error","\nincorrect guest name : None"
else:
return "error",f"\nincorrect guest name : {name}"
elif (service not in luxury) and (name in hotel_guests_name):
if service == "":
return "error","\nincorrect service name : None"
else:
return "error",f"\nincorrect service name : {service}"
else:
if name == "" and service == "":
return "error","\nincorrect guest and service name : None"
elif name == "":
return "error",f"\nincorrect guest and service name : None, {service}"
elif service == "":
return "error",f"\nincorrect guest and service name : {name}, None"
else:
return "error",f"\nincorrect guest and service name : {name}, {service}"
def search_for_client(guests_list,name):
hotel_guests = []
try:
guests_list = guests_list.strip()
except AttributeError:
return "error",f"\nInvalid type for guests_list : {str(type(guests_list)).split(' ')[1].rstrip('>')}, guests_list must be string"
else:
with open(guests_list) as file:
for guest in DictReader(file):
try:
if guest not in hotel_guests and guest["name"].istitle() and guest["adult"].isdecimal() and (int(guest["adult"]) >= 1) and guest["kid"].isdecimal() and (int(guest["kid"]) >= 0) and guest["package"] in ["normal","premium","luxury"] and guest["night"].isdecimal() and (int(guest["night"]) >= 1) and guest["room"].isdecimal():
hotel_guests.append(guest)
except AttributeError:
pass
try:
name = name.strip().lower().title()
except AttributeError:
return "error",f"\nInccorect type for name : {str(type(name)).split(' ')[1].rstrip('>')}, name must be a string"
else:
hotel_guests_name = []
for h_g in hotel_guests:
hotel_guests_name.append(h_g["name"])
if name in hotel_guests_name:
for hg in hotel_guests:
if name == hg["name"]:
return "correct",f"\nName : {hg['name']} \nPackage : {hg['package']} \nNumber of adults : {hg['adult']} \nNumber of kids : {hg['kid']} \nNumber of staying nights : {hg['night']} \nRoom number : {hg['room']}"
else:
if name == "":
return "error","\nInvlaid guest name : None, None is not the hotels guest"
else:
return "error",f"\nInvlaid guest name : {name}, {name} is not the hotels guest"
def remove_guest(name):
global hotel_guests
try:
name = name.strip().lower().title()
except AttributeError:
pass
else:
for index in range(len(hotel_guests)):
if hotel_guests[index]["name"] == name:
del hotel_guests[index]
break
with open("hotel_guests_list.csv","w") as file:
writer = DictWriter(file, fieldnames=["name","adult","kid","package","night","room"])
writer.writeheader()
for guest in sorted(hotel_guests, key=lambda guest: guest["name"]):
writer.writerow(guest)
def logout():
if (len(hotel_guests) + len(empty_rooms)) == hotel_room_limit:
cprint("\nThere is no missing or excess data in the database","green")
elif (len(hotel_guests) + len(empty_rooms)) < hotel_room_limit:
cprint(f"\nThere is {hotel_room_limit - (len(hotel_guests) + len(empty_rooms))} missing room in empty rooms list or guests in hotel guests list","red")
else:
cprint(f"\nThere is {(len(hotel_guests) + len(empty_rooms)) - hotel_room_limit} more room or guest in the database","red")
exit("")
if __name__=="__main__":
main()