def book_a_cage(): print(' ****************** Book a cage **************** ') if not state.active_account: error_msg("You must log in first to book a cage") return snakes = svc.get_snakes_for_user(state.active_account.id) if not snakes: error_msg('You must first [a]dd a snake before you can book a cage.') return print("Let's start by finding available cages.") start_text = input("Check-in date [yyyy-mm-dd]: ") if not start_text: error_msg('cancelled') return checkin = parser.parse( start_text ) checkout = parser.parse( input("Check-out date [yyyy-mm-dd]: ") ) if checkin >= checkout: error_msg('Check in must be before check out') return print() for idx, s in enumerate(snakes): print('{}. {} (length: {}, venomous: {})'.format( idx + 1, s.name, s.length, 'yes' if s.is_venomous else 'no' )) snake = snakes[int(input('Which snake do you want to book (number)')) - 1] cages = svc.get_available_cages(checkin, checkout, snake) print("There are {} cages available in that time.".format(len(cages))) for idx, c in enumerate(cages): print(" {}. {} with {}m carpeted: {}, has toys: {}.".format( idx + 1, c.name, c.square_meters, 'yes' if c.is_carpeted else 'no', 'yes' if c.has_toys else 'no')) if not cages: error_msg("Sorry, no cages are available for that date.") return cage = cages[int(input('Which cage do you want to book (number)')) - 1] svc.book_cage(state.active_account, snake, cage, checkin, checkout) success_msg('Successfully booked {} for {} at ${}/night.'.format(cage.name, snake.name, cage.price))
def book_a_cage(): print(' ****************** Book a cage **************** ') if not state.active_account: hosts.error_msg("Must be logged in to register a cage") return snakes = svc.get_snakes_for_user(state.active_account.id) if not snakes: hosts.error_msg( f'No snakes found for user {state.active_account.name}') return start_text = input("Check-in date for cage [yyyy-mm-dd]: ") if not start_text: hosts.error_msg('Cancelled') return check_in_date = parser.parse(start_text) checkout_date = parser.parse( input("Checkout date for cage [yyyy-mm-dd]: ")) if check_in_date >= checkout_date: hosts.error_msg('Check in date must be prior to checkout date') return print('Select snake to book:') view_your_snakes(show_header=False) snake_number = int(input("Enter snake number: ")) - 1 snake = snakes[snake_number] print('Finding available cages...') cages = svc.get_available_cages(check_in_date, checkout_date, snake) if not cages: hosts.error_msg('No cages available for your date') return print( f'You have {len(cages)} available cage(s) to book. Please select from the following:' ) for idx, c in enumerate(cages): print( f" * {idx + 1}. {c.name}, size: {c.square_metres}m\N{SUPERSCRIPT TWO}, " f"carpeted: {'yes' if c.is_carpeted else 'no'}, " f"toys: {'yes' if c.has_toys else 'no'}, " f"price: {c.price}") cage = cages[int(input('Select cage to book: ')) - 1] cage = svc.book_cage(state.active_account, snake, cage, check_in_date, checkout_date) hosts.success_msg( f'Successfully booked {cage.name} for {snake.name} at £{cage.price}/night' )
def book_a_cage(): print(' ****************** Book a cage **************** ') # Require an account if not state.active_account: print(f"You have to be logged in") return # Verifying that user have a snake snakes = svc.get_snakes_for_user(state.active_account) if not snakes: print("You should frist [a]dd snakes in before booking a cage") # TODO: Get dates and select snake print("Lets check for available bookings") start_date = input("Enter check in date [yyyy-mm-dd]") if not start_date: print("cancelled") return check_in = parser.parse(start_date) checcheck_out = parser.parse(input("Enter check in date [yyyy-mm-dd]")) if check_in > check_out: print("Error: check_in must be before check_out") return snakes = svc.get_snakes_for_user(state.active_account) for idx, s in enumerate(snakes): print(" {} - {} -> {}m long and {}venomous".format( idx + 1, s.name, s.length, '' if s.is_venomous else 'not ')) snake = snakes[int(input('Enter snake number that you wish to book')) - 1] # Find cages available across date range for our particular snake attributes cages = svc.get_available_cages(check_in, check_out, snake) print(f"You snake can be booked in {len(cages)} cages ") for idx, c in enumerate(cages): print( "{} - {c.name} is {c.square_meters} meters. Carpeted = {}, Has Toys = {}" .format(idx + 1, c.name, c.square_meters, "YES" if c.is_carpeted else 'NO', "YES" if c.has_toys else 'NO')) if not cages: print("No cages that can be booked") return cage = cages[int(input('Enter cage number that you wish to book')) - 1] svc.book_cage(snake, cage, checkin, checkout) print("successfully nooked a new cage")
def book_a_cage(): print(' ****************** Book a cage **************** ') if not state.active_account: error_msg('You must login first to book a cage.') return snakes = svc.get_snakes_for_user(state.active_account.id) if not snakes: error_msg('You must first [a]dd a snake before you can book a cage.') return print("Let's start by finding available cages") start_text = input("Check in date [yyyy-mm-dd]? ") if not start_text: error_msg('Cancelled') return checkin = parser.parse(start_text) checkout = parser.parse(input("Check out date [yyyy-mm-dd]? ")) if checkin > checkout: error_msg('Check in must be before checkout') return print() for idx, s in enumerate(snakes): print(f"{(idx + 1)}. {s.name} (length: {s.length}m, " f"venomous: {('yes' if s.is_venomous else 'no')})") snake = snakes[int(input("Which snake do you want book for (number)")) - 1] cages = svc.get_available_cages(checkin, checkout, snake) if not cages: error_msg('Sorry, no cages available for that date') print(f"There are {len(cages)} available during that time.") for idx, c in enumerate(cages): print(f" {(idx + 1)}. {c.name} with {c.square_meters}m, " f"carpeted: {('yes' if c.is_carpeted else 'no')}" f"has toys: {('yes' if c.has_toys else 'no')}.") cage = cages[int(input('Which cage would you like to book (number)? ')) - 1] svc.book_cage(state.active_account, snake, cage, checkin, checkout) success_msg(f"Successfully booked {cage.name} for {snake.name} " f"at €{cage.price} per night.")