Пример #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.")
    try:
        checkin = parser.parse(input("Check-in date [yyyy-mm-dd]: "))
        checkout = parser.parse(input("Check-out date [yyyy-mm-dd]: "))
    except:
        error_msg('Invalid inputs')
        return

    checkout = checkout + datetime.timedelta(days=1) - datetime.timedelta(
        seconds=1)
    if checkin >= checkout:
        error_msg('Check in must be before check out')
        return

    print()
    view_your_snakes(suppress_header=True)
    print()

    try:
        snake = snakes[int(input('Which snake do you want to book (number)')) -
                       1]
    except:
        error_msg('Invalid inputs')
        return

    cages = svc.get_available_cages(checkin, checkout, snake)

    print("There are {} cages available in that time.".format(len(cages)))
    print()
    for idx, c in enumerate(cages):
        print(" {}. {} with {}sq.m at ${}/night. carpeted: {}, has toys: {}.".
              format(idx + 1, c.name, c.square_meters, c.price,
                     '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
    try:
        cage = cages[int(input('Which cage do you want to book (number)')) - 1]
    except:
        error_msg('Invalid inputs')
        return

    svc.book_cage(state.active_account, snake, cage, checkin, checkout)

    success_msg('Successfully booked {} for {} at ${}/night.'.format(
        cage.name, snake.name, cage.price))
Пример #2
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 '))
def book_a_cage():
    print(" ****************** Book a cage **************** ")
    if not state.active_account:
        error_msg("You must log in first to add a snake")
        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("Canceled")
        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("{}. {} (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 during 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 view_your_snakes(suppress_header=False):
    if not suppress_header:
        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 idx, s in enumerate(snakes):
        print(Fore.LIGHTBLUE_EX + 'Snake no : ' + str(idx + 1) + Fore.WHITE)
        print(f'name : {s.name}')
        print(f'species : {s.species}')
        print(f'length : {s.length}')
        print(f'Venomous? : {s.is_venomous}')
Пример #5
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:
        # 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))
Пример #6
0
def view_bookings():
    print(' ****************** Your bookings **************** ')
    if not state.active_account:
        error_msg("You must log in first to view 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)
    print()
    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 +
             datetime.timedelta(seconds=1)).days))
def view_bookings():
    print(" ****************** Your bookings **************** ")
    if not state.active_account:
        error_msg("You must log in first to add a snake")
        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,
            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,
        ))