Exemplo n.º 1
0
def handler_to_choose_category(update: Update, context: CallbackContext):
    text = update.message.text
    with session_scope() as session:
        user = session.query(User).filter(User.telegram_user_id == update.message.from_user.id).first()
        categories = CategoryEarning.get_all_categories_by_text(session, user.id)
    if text in categories:
        with session_scope() as session:
            add_earning_in_db(session,
                              update.message.from_user.id,
                              context.user_data['amount_money_earning'],
                              text)
        bot.send_message(chat_id=update.message.from_user.id,
                         text=text_success_add_earning(),
                         reply_markup=ReplyKeyboardRemove())
        return ConversationHandler.END
Exemplo n.º 2
0
 def wrapped(update, context, *args, **kwargs):
     telegram_user = update.message.from_user
     with session_scope() as session:
         user = session.query(User).filter(User.telegram_user_id == update.message.from_user.id).first()
         username = getattr(telegram_user, 'username', sqlalchemy.null())
         user.update_username(session, username)
     return func(update, context, *args, **kwargs)
Exemplo n.º 3
0
def job_backup_database(context: CallbackContext):
    if datetime.datetime.now().weekday() != 6:
        return
    with session_scope() as session:
        admin_users = session.query(User).filter(
            User.telegram_user_id.in_(config['admin_list'])).all()
        for user in admin_users:
            send_database(user.telegram_user_id)
Exemplo n.º 4
0
def handler_edit_category(update: Update, context: CallbackContext):
    with session_scope() as session:
        categories = context.user_data[
            'category_manager'].get_all_categories_by_text(
                session, update.message.from_user.id)
    answer = update.message.text
    if answer in categories:
        context.user_data['old_edit_category'] = answer
        return to_write_edit_category(update, context)
Exemplo n.º 5
0
def handler(update: Update, context: CallbackContext):
    with session_scope() as session:
        user = User.get_user_by_telegram_user_id(session,
                                                 update.message.from_user.id)
        text = make_text_today(session, datetime.datetime.now(), user)
    bot.send_message(
        chat_id=update.message.from_user.id,
        text=text,
        parse_mode=telegram.ParseMode.HTML,
    )
Exemplo n.º 6
0
def send_message_to_choose_category(telegram_user_id, amount_money):
    with session_scope() as session:
        user = session.query(User).filter(User.telegram_user_id == telegram_user_id).first()
        buttons = make_buttons_for_choose_category(count_buttons_per_row=config['buttons_per_row'],
                                                   categories=CategoryEarning.get_all_categories(session, user.id))
    buttons = add_buttons_exit_and_back(buttons)
    keyboard = ReplyKeyboardMarkup(buttons, resize_keyboard=True)
    bot.send_message(chat_id=telegram_user_id,
                     text=text_to_choose_category(amount_money),
                     parse_mode=telegram.ParseMode.HTML,
                     reply_markup=keyboard)
Exemplo n.º 7
0
def handler_confirm_add_category(update: Update, context: CallbackContext):
    if update.message.text == Buttons.confirm:
        with session_scope() as session:
            new_category = context.user_data['add_category']
            context.user_data['category_manager'].add_category_in_db(
                session, new_category, update.message.from_user.id)
        bot.send_message(chat_id=update.message.from_user.id,
                         text=context.user_data['category_manager'].
                         text_success_add_category(new_category),
                         parse_mode=telegram.ParseMode.HTML,
                         reply_markup=ReplyKeyboardRemove())
        return entry_point(update, context)
Exemplo n.º 8
0
def handler_confirm_delete_transaction(update: Update,
                                       context: CallbackContext):
    if update.message.text == Buttons.confirm:
        with session_scope() as session:
            context.user_data['transaction_deleter'].delete_transaction(
                session)
        bot.send_message(chat_id=update.message.from_user.id,
                         text=context.user_data['transaction_deleter'].
                         make_text_success_delete_transaction(),
                         reply_markup=ReplyKeyboardRemove(),
                         parse_mode=telegram.ParseMode.HTML)
        return ConversationHandler.END
Exemplo n.º 9
0
def to_menu_manage_categories(update, context):
    context.user_data['back_func'] = to_choose_earning_or_consumption
    with session_scope() as session:
        text = TextMenuManageCategories.make_text_menu_manage_categories(
            session, update.message.from_user.id,
            context.user_data['category_manager'])
        keyboard = make_keyboard_menu_manage_categories(
            session, update.message.from_user.id,
            context.user_data['category_manager'])
    bot.send_message(chat_id=update.message.from_user.id,
                     text=text,
                     reply_markup=keyboard,
                     parse_mode=telegram.ParseMode.HTML)
    return States.TO_MENU_MANAGE_CATEGORIES
Exemplo n.º 10
0
def to_edit_category(update: Update, context: CallbackContext):
    context.user_data['back_func'] = to_menu_manage_categories
    with session_scope() as session:
        categories = context.user_data['category_manager'].get_all_categories(
            session, update.message.from_user.id)
        buttons = make_buttons_for_choose_category(config['buttons_per_row'],
                                                   categories)
    bot.send_message(chat_id=update.message.from_user.id,
                     text=text_edit_category(),
                     reply_markup=ReplyKeyboardMarkup(
                         add_buttons_exit_and_back(buttons),
                         resize_keyboard=True),
                     parse_mode=telegram.ParseMode.HTML)
    return States.TO_EDIT_CATEGORY
Exemplo n.º 11
0
def job_results(context: CallbackContext):
    now = datetime.datetime.now()
    with session_scope() as session:
        users = session.query(User).all()
        for user in users:
            if user_has_earning_or_consumption_today(user, now):
                today_results = make_text_today(session, now, user)
                bot.send_message(
                    chat_id=user.telegram_user_id,
                    text=today_results,
                    parse_mode=telegram.ParseMode.HTML,
                )

            if is_time_to_week_results(now):
                if user_has_earning_or_consumption_current_week(user, now):
                    week_results = make_text_week_results(session, now, user)
                    bot.send_message(chat_id=user.telegram_user_id,
                                     text=week_results,
                                     parse_mode=telegram.ParseMode.HTML)
Exemplo n.º 12
0
def to_confirm_delete_transaction(update: Update, context: CallbackContext):
    with session_scope() as session:
        if context.user_data['transaction_deleter'].check_exist_transaction(
                session):
            bot.send_message(chat_id=update.message.from_user.id,
                             text=context.user_data['transaction_deleter'].
                             make_text_delete_transaction(session),
                             reply_markup=ReplyKeyboardMarkup(
                                 add_button_exit([[Buttons.confirm]]),
                                 resize_keyboard=True),
                             parse_mode=telegram.ParseMode.HTML)
            return States.TO_CONFIRM_DELETE_TRANSACTION

    bot.send_message(
        chat_id=update.message.from_user.id,
        text=context.user_data['transaction_deleter'].
        text_error_id_transaction(),
    )
    return exit_point(update, context)
Exemplo n.º 13
0
 def wrapped(update, context, *args, **kwargs):
     with session_scope() as session:
         user = session.query(User).filter(
             User.telegram_user_id == update.message.from_user.id).first()
         user.update_activity(session, datetime.datetime.now())
     return func(update, context, *args, **kwargs)
Exemplo n.º 14
0
def create_default_categories_for_earning_and_consumption(telegram_user_id):
    with session_scope() as session:
        user = session.query(User).filter(User.telegram_user_id == telegram_user_id).first()
        CategoryEarning.create_default_categories(session, user.id)
        CategoryConsumption.create_default_categories(session, user.id)