async def cmd_add_spends(message: types.Message): keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True) spends = db.select_categories() buttons = ["Type", "Back"] lst = buttons + spends for item in lst: keyboard.add(item) spends_ = "\n".join(str(el) for el in spends) spends_clear = spends_.replace('(', '').replace(')', '').replace("'", "") await message.answer( f"{spends}Please, choose one category.\nOr choose 'Type'", reply_markup=keyboard, parse_mode=types.ParseMode.HTML)
async def cmd_month_stat(message: types.Message): username = message.chat.username categories = db.select_categories() stat = list() total = 0 for category in categories: month_stat = db.get_month_statistics(username, category) if month_stat is None: continue else: total = total + month_stat newtup = (category, month_stat) stat.append(newtup) spends_ = "\n".join(str(el) for el in stat) spends_clear = spends_.replace('(', '').replace(')', '').replace("'", "") await message.answer(f"<u>{spends_clear}</u>\n<b>Total\n{total}</b>", parse_mode=types.ParseMode.HTML)
async def cmd_type_spends(message: types.Message, state: FSMContext): username = message.chat.username message_raw = str(message.text) message_split = message_raw.split() amount = message_split[1] category = message_split[0] categories = db.select_categories() if category in categories: amount = float(message_split[1]) write = db.add_spend(username, category, amount) await state.finish() await message.answer( f"<u>Categoty: {message_split[0]}\n" f"Spends: {message_split[1]}</u>\n<b>{write}</b>", parse_mode=types.ParseMode.HTML) else: await message.answer(f"{username} Please use existing categories!")
lst = buttons + spends for item in lst: keyboard.add(item) spends_ = "\n".join(str(el) for el in spends) spends_clear = spends_.replace('(', '').replace(')', '').replace("'", "") await message.answer( f"{spends}Please, choose one category.\nOr choose 'Type'", reply_markup=keyboard, parse_mode=types.ParseMode.HTML) """By category""" user_data = {} @dp.message_handler(text=db.select_categories()) async def text_in_handler(message: types.Message): user_data[message.chat.username] = message.text category = message.text await Form2.spends_write.set() await message.answer( f"Please write amount for category:\n<b>{category}</b>", parse_mode=types.ParseMode.HTML) @dp.message_handler(state=Form2.spends_write) async def cmd_write_spends(message: types.Message, state: FSMContext): username = message.chat.username spends = message.text category = user_data[message.chat.username] write = db.add_spend(username, category, spends)