Пример #1
0
async def process_add_category(message: types.Message, state: FSMContext):
    user_id = message.from_user.id
    category = message.text
    if await postgres.select_user_categories(user_id) is False:
        await postgres.create_user_category(user_id=user_id, category=category)
        await state.finish()
        await bot.edit_message_text(chat_id=user_id,
                                    message_id=msg_id,
                                    reply_markup=buttons.all_buttons(),
                                    text=answers.category_added)

    elif category in await postgres.select_user_categories(user_id):
        await state.finish()
        await bot.edit_message_text(chat_id=user_id,
                                    message_id=msg_id,
                                    reply_markup=buttons.all_buttons(),
                                    text=answers.category_exists)

    else:
        await postgres.create_user_category(user_id=user_id, category=category)
        await state.finish()
        await bot.edit_message_text(chat_id=user_id,
                                    message_id=msg_id,
                                    reply_markup=buttons.all_buttons(),
                                    text=answers.category_added)
Пример #2
0
async def process_start_command(message: types.Message):
    user_id = message.from_user.id
    if not await postgres.select_user_categories(user_id=user_id):
        await message.answer(text=await
                             answers.manual_text(message.from_user.first_name),
                             reply_markup=buttons.all_buttons())
    elif not await postgres.get_balance(user_id=user_id):
        await message.answer(text=await
                             answers.manual_text(message.from_user.first_name),
                             reply_markup=buttons.all_buttons())
    else:
        await message.answer(answers.start, reply_markup=buttons.all_buttons())
Пример #3
0
async def process_get_day(callback_query: types.CallbackQuery):
    user_id = callback_query.from_user.id
    date = datetime.datetime.now().date()
    message = await postgres.get_day(user_id=user_id, date=date)
    if not message:
        await bot.edit_message_text(
            chat_id=callback_query.from_user.id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.day_expense_false)
    else:
        await bot.edit_message_text(
            chat_id=callback_query.from_user.id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=message)
Пример #4
0
async def process_show_drops(callback_query: types.CallbackQuery,
                             state: FSMContext):
    user_id = callback_query.from_user.id
    await bot.edit_message_text(chat_id=user_id,
                                message_id=callback_query.message.message_id,
                                reply_markup=buttons.all_buttons(),
                                text=answers.cancel)
    await state.finish()
Пример #5
0
async def process_show_categories(callback_query: types.CallbackQuery):
    user_id = callback_query.from_user.id
    answer = ''
    if not await postgres.select_user_categories(user_id=user_id):
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.category_exists_false)
    else:
        for category in await postgres.select_user_categories(user_id=user_id):
            answer += category + '\n'
        # тут можно протестировать отрисовку большого количества кнопок
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answer)
Пример #6
0
async def process_delete_expense_from_last_five(
        callback_query: types.CallbackQuery, state: FSMContext):
    user_id = callback_query.from_user.id
    expense_id = callback_query.data.split(':')[2]
    await postgres.delete_expense(expense_id=expense_id, user_id=user_id)
    await state.finish()
    await bot.edit_message_text(chat_id=user_id,
                                message_id=callback_query.message.message_id,
                                reply_markup=buttons.all_buttons(),
                                text=answers.expense_deleted)
Пример #7
0
async def process_delete_category(callback_query: types.CallbackQuery,
                                  state: FSMContext):
    user_id = callback_query.from_user.id
    category = callback_query.data.split(':')[2]
    await postgres.delete_user_category(user_id=user_id, category=category)
    await state.finish()
    await bot.edit_message_text(chat_id=user_id,
                                message_id=callback_query.message.message_id,
                                reply_markup=buttons.all_buttons(),
                                text='Категория {0} удалена'.format(category))
Пример #8
0
async def process_choose_category_expense(callback_query: types.CallbackQuery,
                                          state: FSMContext):
    user_id = callback_query.from_user.id
    global msg_id
    msg_id = callback_query.message.message_id

    if not await postgres.get_balance(user_id=user_id):

        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.balance_exists_false)
    else:
        await User_states.choose_category.set()
        async with state.proxy() as data:
            data['category'] = callback_query.data.split(':')[2]
        await User_states.next()
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.input_number)
Пример #9
0
async def process_get_report(callback_query: types.CallbackQuery):
    user_id = callback_query.from_user.id
    report = await postgres.get_report(user_id=user_id)
    if not report:
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.report_false)
    else:
        xls_report = open("{0}.xls".format(user_id), 'rb')
        await bot.send_document(chat_id=callback_query.from_user.id,
                                document=xls_report,
                                caption='Ваш отчёт за всё время '
                                'использования бота')
        xls_report.close()
        """await bot.edit_message_text(chat_id=user_id,
Пример #10
0
async def process_show_last_five(callback_query: types.CallbackQuery,
                                 state: FSMContext):
    user_id = callback_query.from_user.id
    msg_id = callback_query.message.message_id
    if not await postgres.get_last_five(user_id):
        await state.finish()
        await bot.edit_message_text(chat_id=user_id,
                                    message_id=msg_id,
                                    reply_markup=buttons.all_buttons(),
                                    text=answers.expenses_exists_false)
    else:
        last_five_expenses = await postgres.get_last_five(user_id)
        keyboard = buttons.last_five(last_five_expenses)
        await bot.edit_message_text(chat_id=user_id,
                                    message_id=msg_id,
                                    reply_markup=keyboard,
                                    text=answers.choose_expense_to_delete)
Пример #11
0
async def process_add_expense(callback_query: types.CallbackQuery):
    user_id = callback_query.from_user.id
    if not await postgres.select_user_categories(user_id):
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=buttons.all_buttons(),
            text=answers.category_exists_false)
    else:
        user_categories = await postgres.select_user_categories(user_id)
        keyboard = buttons.choose_category_expense(
            categories_list=user_categories)
        await bot.edit_message_text(
            chat_id=user_id,
            message_id=callback_query.message.message_id,
            reply_markup=keyboard,
            text=answers.please_choose_category)
Пример #12
0
async def process_record_user_expense(message: types.Message,
                                      state: FSMContext):
    await state.update_data(expence=message.text)

    user_id = message.from_user.id
    date = datetime.datetime.now().date()
    async with state.proxy() as data:
        bot_message = data['category'] + ' ' + data['expence']
        user_input = await parse_user_expence(data['expence'])
        expense_data = {
            'user_id': user_id,
            'category': data['category'],
            'merchandise': user_input['merchandise'],
            'price': user_input['price'],
            'date': date
        }
        await postgres.add_user_expense(expense_data)
        # передать 'expence' в парсер, выделить в нём цену, большая цифра -
        # это цена, остальное - товар/услуга
        await bot.edit_message_text(chat_id=message.from_user.id,
                                    message_id=msg_id,
                                    reply_markup=buttons.all_buttons(),
                                    text=bot_message)
    await state.finish()
Пример #13
0
async def process_input_invalid(message: types.Message):
    await bot.edit_message_text(chat_id=message.from_user.id,
                                message_id=msg_id,
                                reply_markup=buttons.all_buttons(),
                                text=answers.invalid_input)