ВОТ САМ КОД:
from aiogram import types
from dispatcher import dp
import handlers.config as config
import re
from bot import BotDB
@dp.message_handler(commands = "start")
async def start(message: types.Message):
if(not BotDB.user_exists(message.from_user.id)):
BotDB.add_user(message.from_user.id)
await message.bot.send_message(message.from_user.id, "Добро пожаловать! Меня зовут Бухгалтер.")
@dp.message_handler(commands = ("spent", "s", "earned", "e"), commands_prefix = "/!")
async def record(message: types.Message):
cmd_variants = (('/spent', '/s', '!spent', '!s'), ('/earned', '/e', '!earned', "!e"))
operation = '-' if message.text.startswith(cmd_variants[0]) else '+'
value = message.text
for i in cmd_variants:
for j in i:
value = value.replace(j, '').strip()
if(len(value)):
x = re.findall(r"\d+(?:.\d+)?", value)
if(len(x)):
value = float(x[0].replace(',', '.'))
BotDB.add_record(message.from_user.id, operation, value)
if(operation == '-'):
await message.reply('✅ Запись о <u><b>расходе</b></u> успешно внесена!')
else:
await message.reply('✅ Запись о <u><b>доходе</b></u> успешно внесена!')
else:
await message.reply('Не удалось определить сумму!')
else:
await message.reply("Не введена сумма!")
@dp.message_handler(commands = ("history", "h"), commands_prefix = "/!")
async def history(message: types.Message):
cmd_variants = ('/history', '/h', '!spent', '!s')
within_als = {
"day": ('today', 'day', 'сегодня', 'день'),
"month": ('month', 'месяц'),
"year": ('year', 'год')
}
cmd = message.text
for r in cmd_variants:
cmd = cmd.replace(r, '').strip()
within = 'day' # по умолчанию
if(len(cmd)):
for k in within_als:
for als in within_als[k]:
if(als == cmd):
within = k
# fetch
records = BotDB.add_records(message.from_user.id, within)
if(len(records)):
answer = f"🕐История операций за {within_als[within][-1]}\n\n"
for r in records:
answer += "<b>" + ("👛 Расход" if not r[2] else "Доход") + "</b>"
answer += f" - {r[3]}"
answer += f" <i>({r[4]})</i>\n"
await message.reply(answer)
else:
await message.reply("Записей не обнаружено!")
А ВОТ ОШИБКА:
PS C:\Users\е\Desktop\python> & "C:/Program Files/Python39/python.exe" c:/Users/е/Desktop/python/handlers/personal_actions.py
Traceback (most recent call last):
File "c:\Users\е\Desktop\python\handlers\personal_actions.py", line 2, in <module>
from dispatcher import dp
ImportError: cannot import name 'dp' from 'dispatcher' (c:\Users\е\Desktop\python\handlers\dispatcher.py)