示例#1
0
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:
        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 **************** ')
    # Require an account
    if not state.active_account:
        error_msg('You must [l]ogin first to book a cage.')
        return

    # Verify they have a snake
    snakes = svc.find_snakes_for_user(state.active_account)
    if len(snakes) < 1:
        error_msg('You must first [a]dd a snake before booking a cage.')
        return

    # Select snake
    list_snakes(suppress_header=True)
    snake_number = input('Enter snake number: ').strip()
    if not snake_number:
        error_msg('Cancelled')
        return
    snake_number = int(snake_number)

    snakes = svc.find_snakes_for_user(state.active_account)
    selected_snake = snakes[snake_number - 1]
    success_msg(f'Booking a cage for {selected_snake.name}.')

    # Get dates
    check_in_date = parser.parse(input('Check-in date [yyyy-mm-dd]: '))
    check_out_date = parser.parse(input('Check-out date [yyyy-mm-dd]: '))

    if check_in_date >= check_out_date:
        error_msg('Check in must be before check out.')
        return

    # Find cages available across date range
    cages = svc.find_available_cages(check_in_date, check_out_date,
                                     selected_snake)

    # Let user select cage to book
    print(f'There are {len(cages)} cages available for those dates.')
    for idx, c in enumerate(cages):
        print(f' {idx+1}. ${c.price} - {c.name},'
              f' {c.square_meters} square meters,'
              f' it does{"" if c.carpeted else " not"} have carpet,'
              f' it does{"" if c.has_toys else " not"} have toys.')
    if not cages:
        error_msg('Sorry, no cages are available for that date.')
        return

    cage_number = int(input('Which cage would you like to book? '))
    selected_cage = cages[cage_number - 1]
    svc.book_cage(state.active_account, selected_cage, selected_snake,
                  check_in_date, check_out_date)
    success_msg(
        f'Booked {selected_cage.name} from {check_in_date} to {check_out_date}'
    )
示例#4
0
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")
示例#5
0
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.")
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'
    )
示例#7
0
def book_a_cage():
    print(' ****************** Book a cage **************** ')

    account = state.active_account
    if not account:
        error_msg(f'Please Login or create an account')
        return

    # has_snake = account.snake_ids
    snakes = svc.get_snakes_for_user(account.id)

    if not snakes:
        error_msg('Add a snake to continue')
        return

    # view_your_snakes()

    print("Let's start by finding available cages.")
    start_date = input(
        "Enter the Check-in date in the format :- (dd-mm-yyyy) :- ")

    if not start_date:
        error_msg('cancelled')
        return

    check_in_date = parser.parse(start_date)

    end_date = input(
        "Enter the Check-out date in the format :- (dd-mm-yyyy) :- ")

    if not end_date:
        error_msg('cancelled')
        return

    check_out_date = parser.parse(end_date)

    if check_out_date <= check_in_date:
        print('Sorry! Checkout date cannot be earlier than checkin date')
        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'))

    selected_snake = snakes[
        int(input("select the snake you want to book for - ")) - 1]

    cages = svc.find_available_cages(selected_snake, check_in_date,
                                     check_out_date)

    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.meters, 'yes' if c.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, selected_snake, cage, check_in_date,
                  check_out_date)

    success_msg('Successfully booked {} for {} at ${}/night.'.format(
        cage.name, selected_snake.name, cage.price))