|
| 1 | +import uuid |
| 2 | +import logging |
| 3 | +from datetime import datetime, timedelta |
| 4 | + |
| 5 | +logging.basicConfig( |
| 6 | + format='%(asctime)s - %(levelname)s - %(message)s', |
| 7 | + datefmt='%Y-%m-%d %H:%M:%S', |
| 8 | + level=logging.DEBUG, |
| 9 | + # add streamHandler or fileHandler if needed |
| 10 | + handlers = [ |
| 11 | + logging.StreamHandler(), |
| 12 | + logging.FileHandler('logs/booking.log') # Uncomment to log to a file |
| 13 | + ] |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +logger = logging.getLogger(__name__) |
| 18 | + |
| 19 | +def generate_checkout_date(number_of_days = 1): |
| 20 | + date_today = datetime.now() + timedelta(days = number_of_days) |
| 21 | + return date_today |
| 22 | + |
| 23 | +user_list = { |
| 24 | + '0168154259082': {'age': 45, 'full_name': 'Steven Miller', 'id': '0168154259082'}, |
| 25 | + '1047745271084': {'age': 60, 'full_name': 'Jeffrey Holland', 'id': '1047745271084'}, |
| 26 | + '1474505146084': {'age': 49, 'full_name': 'James Rodriguez', 'id': '1474505146084'}, |
| 27 | + '1536313871081': {'age': 24, 'full_name': 'Lisa Peterson', 'id': '1536313871081'}, |
| 28 | + '1768061462085': {'age': 33, 'full_name': 'Jeffrey Weaver', 'id': '1768061462085'}, |
| 29 | + '1854454228083': {'age': 26, 'full_name': 'Darren Anderson', 'id': '1854454228083'}, |
| 30 | + '3047244456088': {'age': 40, 'full_name': 'Jeremy Peterson', 'id': '3047244456088'}, |
| 31 | + '3527653046089': {'age': 29, 'full_name': 'Jeffrey Kramer', 'id': '3527653046089'}, |
| 32 | + '3541180845084': {'age': 38, 'full_name': 'Michelle Garcia', 'id': '3541180845084'}, |
| 33 | + '5132921360089': {'age': 54, 'full_name': 'Anna Wood', 'id': '5132921360089'}, |
| 34 | + '5470790388087': {'age': 51, 'full_name': 'Brian Stevens', 'id': '5470790388087'}, |
| 35 | + '6235335312080': {'age': 26, 'full_name': 'Christina Kelly', 'id': '6235335312080'}, |
| 36 | + '6292344283081': {'age': 27, 'full_name': 'Amber Garcia', 'id': '6292344283081'}, |
| 37 | + '6930543883084': {'age': 60, 'full_name': 'Amy Jones', 'id': '6930543883084'}, |
| 38 | + '7078761819086': {'age': 58, 'full_name': 'Dr. Matthew Carpenter', 'id': '7078761819086'}, |
| 39 | + '7572026002087': {'age': 35, 'full_name': 'Susan Carpenter', 'id': '7572026002087'}, |
| 40 | + '8265805005085': {'age': 47, 'full_name': 'Joe Bishop', 'id': '8265805005085'}, |
| 41 | + '8988902781080': {'age': 36, 'full_name': 'Michael Hale', 'id': '8988902781080'}, |
| 42 | + '9037816322084': {'age': 21, 'full_name': 'Scott Franklin', 'id': '9037816322084'}, |
| 43 | + '9760205353082': {'age': 32, 'full_name': 'Angelica Johnson', 'id': '9760205353082'} |
| 44 | +} |
| 45 | + |
| 46 | +class Booking: |
| 47 | + def __init__(self, |
| 48 | + age=23, |
| 49 | + id = "9760205353087", |
| 50 | + full_name = "John Doe", |
| 51 | + room_number = 1, check_in_date = datetime.now(), |
| 52 | + check_out_date = generate_checkout_date(2)): |
| 53 | + self.id = id |
| 54 | + self.age = age |
| 55 | + self.full_name = full_name |
| 56 | + self.room_number = room_number |
| 57 | + self.check_in_date = check_in_date |
| 58 | + self.check_out_date = check_out_date |
| 59 | + self.booking_reference = str(uuid.uuid4()) |
| 60 | + |
| 61 | + def __str__(self): |
| 62 | + return f"Booking(full_name={self.full_name}, id={self.booking_reference})" |
| 63 | + |
| 64 | + |
| 65 | +class ReversationSystem: |
| 66 | + def __init__(self, total_bookings_per_day = 20): |
| 67 | + self.bookings = {} |
| 68 | + self.TOTAL_BOOKINGS_PER_DAY = total_bookings_per_day |
| 69 | + self.user_list = user_list |
| 70 | + |
| 71 | + def book_for_user_by_id(self, id_number: str, number_of_days = 1, number_of_rooms = 1): |
| 72 | + """ |
| 73 | + Docstring for book_for_user_by_id |
| 74 | + |
| 75 | + :param self: book a hotel by user id |
| 76 | + :param id_number: User Id number from DHA |
| 77 | + :type id_number: str |
| 78 | + :param number_of_days: Number of days booked for |
| 79 | + :param number_of_rooms: Number of rooms booked for |
| 80 | + """ |
| 81 | + if id_number not in self.user_list: |
| 82 | + raise Exception("User must be registered with Home Affairs") |
| 83 | + elif id_number in self.bookings: |
| 84 | + raise Exception(f"{ id_number } is already booked, try increasing rooms instead") |
| 85 | + elif self.is_fully_booked(): |
| 86 | + raise Exception(f"Hotel is fully booked") |
| 87 | + |
| 88 | + booking = Booking(**self.user_list[id_number]) |
| 89 | + booking_info = self.bookings[id_number] = { |
| 90 | + "booking": booking, |
| 91 | + "booking_reference": booking.booking_reference, |
| 92 | + "number_of_rooms": number_of_rooms, |
| 93 | + "number_of_days": number_of_days, |
| 94 | + } |
| 95 | + logger.debug(f"User with id_number: {id_number} has successfully booking a hotel, reference: {booking.booking_reference}") |
| 96 | + logger.debug( booking_info ) |
| 97 | + return booking_info |
| 98 | + |
| 99 | + |
| 100 | + def is_fully_booked(self): |
| 101 | + return False |
| 102 | + |
0 commit comments