Esempio n. 1
0
def check_confirmation(update, context):
    now = datetime.now()
    two_hours = now + timedelta(days=2)
    reservation = sess.query(Reservation).filter(
        Reservation.day <= two_hours, Reservation.is_expired != True,
        Reservation.is_confirmed != True).order_by(Reservation.day).first()
    if reservation:
        response = "Your reservation No `" + str(
            reservation.id_) + " " + reservation.day.strftime(
                '%Y-%m-%d %H:%M') + "`"
        if update.message.text == '❌ Cancel':
            sess.delete(reservation)
            sess.commit()
            response += ' cancelled'
        elif update.message.text == '✅ Confirm':
            reservation.is_confirmed = True
            sess.commit()
            response += ' confirmed'
        update.message.reply_text(response,
                                  reply_markup=ReplyKeyboardMarkup(
                                      main_menu,
                                      resize_keyboard=True,
                                      one_time_keyboard=True),
                                  parse_mode=ParseMode.MARKDOWN)
        return True
    else:
        unknown(update, context)
Esempio n. 2
0
def cancel_reservation(update, context):
    reservations = sess.query(Reservation).filter_by(
        user_id=update.message.chat.id).order_by(Reservation.day)
    response = "Choose the number of reservation you want to cancel:\n"
    i = 1
    buttons = []
    for res in reservations:
        if res.day.month < date.today().month:
            sess.delete(res)
            continue
        elif res.day.month == date.today(
        ).month and res.day.day < date.today().day:
            sess.delete(res)
            continue
        response += str(i) + ". Date:" + str(res.day) + " Time:" + str(
            res.slot) + "\n"
        buttons.append(str(i))
        i += 1
    userState[update.message.chat.id] = {}
    userState[update.message.chat.id]['reservations'] = i - 1
    if response == "Choose the number of reservation you want to cancel:\n":
        response = "You don't have reservations."
    update.message.reply_text(response,
                              reply_markup=ReplyKeyboardMarkup(
                                  buttons,
                                  resize_keyboard=True,
                                  one_time_keyboard=True))
Esempio n. 3
0
def delete_reservation(update, context):
    if re.match('\d$', update.message.text) is not None:
        num = int(update.message.text)
        if num > userState[update.message.chat.id]['reservations']:
            return False
        x = sess.query(Reservation).filter_by(
            user_id=update.message.chat.id)[num - 1]
        sess.delete(x)
        userState[update.message.chat.id] = {}
        update.message.reply_text('Reservation was canceled.')
        cancel(update, context)
    elif update.message.text == "Cancel":
        cancel(update, context)
Esempio n. 4
0
def choose_hour(update, context):
    hours = get_hours()
    if update.message.text in hours:
        splitted_time = update.message.text.split(':')
        chosen_day = datetime(YEAR, int(context.user_data['month']), int(context.user_data['day']), int(splitted_time[0]), int(splitted_time[1]), 0)
        check = sess.query(Reservation).filter_by(
            day=chosen_day,
            slot=update.message.text
        ).first()
        if check is None:
            res = Reservation(
                user_id=update.message.chat.id,
                day=chosen_day,
                slot=update.message.text
            )
            sess.add(res)
            waitinglist = sess.query(WaitingList).filter(
                WaitingList.user_id == update.message.chat.id,
                WaitingList.day == date(chosen_day.year, chosen_day.month, chosen_day.day),
            ).first()
            if waitinglist:
                sess.delete(waitinglist)
            sess.commit()

            text = 'Time `' + chosen_day.strftime("%Y-%m-%d %H:%M") + '` reserved successfully'
            update.message.reply_text(text, reply_markup=ReplyKeyboardMarkup(base.main_menu, resize_keyboard=True), parse_mode=ParseMode.MARKDOWN)
            return ConversationHandler.END
        update.message.reply_text('This hour is already reserved')
    elif update.message.text == 'Back':
        context.user_data['wrong_day'] = True
        choose_month(update, context)
        return DAY
    elif update.message.text == 'Subscribe to waiting list':
        response = subscribe_user_to_waiting_list(context, update.message.chat.id)
        update.message.reply_text(response, parse_mode=ParseMode.MARKDOWN)
        base.cancel(update, context)
        return ConversationHandler.END
    elif update.message.text == 'Cancel':
        base.cancel(update, context)
        return ConversationHandler.END
    else:
        context.user_data['wrong_hour'] = True
        update.message.reply_text('Wrong hour')
    choose_day(update, context)
    return HOUR
Esempio n. 5
0
def view_reservations(update, context):
    reservations = sess.query(Reservation).filter_by(
        user_id=update.message.chat.id).order_by(Reservation.day)
    response = "You have made the following reservations:\n"
    i = 1
    for res in reservations:
        if res.day.month < date.today().month:
            sess.delete(res)
            continue
        elif res.day.month == date.today(
        ).month and res.day.day < date.today().day:
            sess.delete(res)
            continue
        response += str(i) + ". Date:" + str(res.day) + " Time:" + str(
            res.slot) + "\n"
        i += 1
    if response == "You have that reservations:\n":
        response = "You don't have any reservation."
    update.message.reply_text(response)
    cancel(update, context)