Пример #1
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")
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))
Пример #3
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))
Пример #4
0
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'
    )
Пример #5
0
def view_your_snakes():
    print(' ****************** Your snakes **************** ')
    if not state.active_account:
        error_msg("You must log in first to view your snakes")
        return

    snakes = svc.get_snakes_for_user(state.active_account.id)
    print("You have {} snakes.".format(len(snakes)))
    for s in snakes:
        print(" * {} is a {} that is {}m long and is {}venomous.".format(
            s.name, s.species, s.length, '' if s.is_venomous else 'not '))
Пример #6
0
def view_your_snakes():
    print(' ****************** Your snakes **************** ')

    if not state.active_account:
        hosts.error_msg('You must log in first to add a snake!')
        return

    snakes = svc.get_snakes_for_user(state.active_account.id)
    print('You have {} snakes.'.format(len(snakes)))

    for s in snakes:
        print(' * {} is a {} that is {} meters in length, and is {}venomous.'.
              format(s.name, s.species, s.length,
                     '' if s.is_venomous else 'not '))
Пример #7
0
def view_your_snakes():
    print(' ****************** Your snakes **************** ')

    if not state.active_account:
        error_msg('You must login first to view your snakes.')
        return

    snakes = svc.get_snakes_for_user(state.active_account.id)
    print(f'You have {len(snakes)} snakes.')
    for s in snakes:
        print(
            f" * {s.name} is a {s.species} that is "
            f"{s.length}m long and is {('' if s.is_venomous else 'not ')}venomous."
        )
Пример #8
0
def view_your_snakes():
    print(' ****************** Your snakes **************** ')

    # TODO: Require an account
    if not state.active_account:
        print(f"You have to be logged in")
        return

    # TODO: Get snakes from DB, show details list
    snakes = svc.get_snakes_for_user(state.active_account)
    print(f"You have {len(snakes)} snakes")
    for s in snakes:
        print(" * {} is a {} - {}n long and {} venomous".format(
            s.name, s.species, s.length, '' if s.is_venomous else 'not'))
Пример #9
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 view_your_snakes():
    print(' ****************** Your snakes **************** ')
    if not state.active_account:
        error_msg("You must log in first to view your snakes")
        return

    snakes = svc.get_snakes_for_user(state.active_account.id)
    print("You have {} snakes.".format(len(snakes)))
    for s in snakes:
        print(" * {} is a {} that is {}m long and is {}venomous.".format(
            s.name,
            s.species,
            s.length,
            '' if s.is_venomous else 'not '
        ))
Пример #11
0
def view_your_snakes(show_header=True):
    if show_header:
        print(' ****************** Your snakes **************** ')

    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)
    print(f'You have {len(snakes)} snakes')

    for idx, s in enumerate(snakes):
        print(
            f" {idx + 1}. {s.name} is a {s.species} that is {s.length}m long and is"
            f"{'' if s.is_venomous else ' not'} venomous")
Пример #12
0
def view_bookings():
    print(' ****************** Your bookings **************** ')
    if not state.active_account:
        print(f"You have to be logged in")
        return

    snakes = {s.id: s for s in svc.get_snakes_for_user(state.active_account)}
    bookings = svc.get_bookings_for_user(state.active_account)

    for b in bookings:
        print(" -> Snake: {}, Booked at: {}, From: {} To: {}".format(
            snakes.get(b.guest_snake_id).name, b.cage,
            datetime.date(b.check_in_date.year, b.check_in_date.month,
                          b.check_in_date.day),
            (b.check_out_date - b.check_in_date).days))
Пример #13
0
def view_bookings():
    print(' ****************** Your bookings **************** ')
    if not state.active_account:
        error_msg("You must log in first to register a cage")
        return

    snakes = {s.id: s for s in svc.get_snakes_for_user(state.active_account.id)}
    bookings = svc.get_bookings_for_user(state.active_account.email)

    print("You have {} bookings.".format(len(bookings)))
    for b in bookings:
        print(' * Snake: {} is booked at {} from {} for {} days.'.format(
            snakes.get(b.guest_snake_id).name,
            b.cage.name,
            datetime.date(b.check_in_date.year, b.check_in_date.month, b.check_in_date.day),
            (b.check_out_date - b.check_in_date).days
        ))
def view_bookings():
    print(' ****************** Your bookings **************** ')
    if not state.active_account:
        error_msg("You must log in first to register a cage")
        return

    snakes = {s.id: s for s in svc.get_snakes_for_user(state.active_account.id)}
    bookings = svc.get_bookings_for_user(state.active_account.email)

    print("You have {} bookings.".format(len(bookings)))
    for b in bookings:
        print(' * Snake: {} is booked at {} from {} for {} days.'.format(
            snakes.get(b.guest_snake_id).name,
            b.cage.name,
            datetime.date(b.check_in_date.year, b.check_in_date.month, b.check_in_date.day),
            (b.check_out_date - b.check_in_date).days
        ))
Пример #15
0
def view_your_snakes():
    print(' ****************** Your snakes **************** ')

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

    snakes = svc.get_snakes_for_user(account.id)
    for idx, c in enumerate(snakes):
        print(f'{idx + 1}.')
        print(f'{c.name}')
        print(f'sp.{c.species}')
        if c.is_venomous:
            success_msg(f'Venomous\n')
        else:
            error_msg(f'Venomous')
        print(f'Length: {c.length}\n')
Пример #16
0
def view_bookings():
    print(' ****************** Your bookings **************** ')
    account = state.active_account
    if not account:
        error_msg(f'Please Login or create an account')
        return

    snakes = {s.id: s for s in svc.get_snakes_for_user(account.id)}
    print(snakes)
    bookings = svc.get_bookings_for_user(state.active_account.email)

    print("You have {} bookings.".format(len(bookings)))
    for b in bookings:
        # noinspection PyUnresolvedReferences
        print(' * Snake: {} is booked at {} from {} for {} days.'.format(
            snakes.get(b.guest_snake_id).name, b.cage.name,
            datetime.date(b.check_in_date.year, b.check_in_date.month,
                          b.check_in_date.day),
            (b.check_out_date - b.check_in_date).days))
Пример #17
0
def view_bookings():
    print(' ****************** Your bookings **************** ')

    if not state.active_account:
        error_msg('You must login first to view your bookings.')
        return

    snakes = {
        s.id: s
        for s in svc.get_snakes_for_user(state.active_account.id)
    }
    bookings = svc.get_bookings_for_user(state.active_account.email)

    print(f"You have {len(bookings)} bookings.")
    for b in bookings:
        print(
            f" * Snake: {snakes.get(b.guest_snake_id).name} is booked at"
            f" {b.cage.name} from "
            f"{datetime.date(b.check_in_date.year, b.check_in_date.month, b.check_in_date.day)}"
            f" for {(b.check_out_date - b.check_in_date).days} days.")
Пример #18
0
def view_bookings():
    print(' ****************** Your bookings **************** ')

    if not state.active_account:
        hosts.error_msg("Must be logged in to register a cage")
        return

    snakes = {
        s.id: s
        for s in svc.get_snakes_for_user(state.active_account.id)
    }
    bookings = svc.get_bookings_for_user(state.active_account.id)

    print(f'You have {len(bookings)} booking(s)')
    b: Booking
    for b in bookings:
        hosts.success_msg(
            f' * Snake: {snakes.get(b.guest_snake_id).name} '
            f'is booked in cage {b.cage.name} '
            f'from {datetime.date(b.check_in_date.year, b.check_in_date.month, b.check_in_date.day)} '
            f'for {(b.check_out_date - b.check_in_date).days} days')
Пример #19
0
def view_bookings():
    print(' ****************** Your bookings **************** ')

    if not state.active_account:
        hosts.error_msg('You must log in first to add a snake!')
        return

    # Create a dictionary to allocate all the snakes belonging to each persons
    snakes = {
        s.id: s
        for s in svc.get_snakes_for_user(state.active_account.id)
    }
    bookings = svc.get_bookings_for_user(state.active_account.id)

    print('You have {} bookings.'.format(len(bookings)))
    for b in bookings:
        print(' * Snake: {} is booked at {} from {} for {} days.'.format(
            snakes.get(b.guest_snake_id).name, b.cage.name,
            datetime.date(b.check_in_date.year, b.check_in_date.month,
                          b.check_in_date.day),
            (b.check_out_date - b.check_in_date).days))
Пример #20
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))