analisys
This commit is contained in:
1 parent
0bd622750f
commit
ceb4536118
7 files changed
+361
-226
No files matched your search
@@ -0,0 +1,117 @@
|
|||||||
|
import currencyes
|
||||||
|
from bot import bot
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from database.models import User, Transaction
|
||||||
|
import datetime
|
||||||
|
import locales
|
||||||
|
|
||||||
|
|
||||||
|
# функция для обработки аналитики и построения диаграмм
|
||||||
|
def analysis_month(message):
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.user == User.get(username=message.chat.id),
|
||||||
|
Transaction.month == datetime.datetime.today().strftime('%m')
|
||||||
|
)
|
||||||
|
incomes = 0
|
||||||
|
consuptions = 0
|
||||||
|
for i in transactions:
|
||||||
|
if i.type == 'incom':
|
||||||
|
incomes += i.sum
|
||||||
|
elif i.type == 'consuption':
|
||||||
|
consuptions += i.sum
|
||||||
|
|
||||||
|
vals = [incomes, consuptions]
|
||||||
|
labels = []
|
||||||
|
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
labels = ['Доходы', 'Расходы']
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
labels = ['Incomes', 'Consuptions']
|
||||||
|
|
||||||
|
exp = (0.1, 0)
|
||||||
|
plt.pie(vals, labels=labels, explode=exp, wedgeprops=dict(width=0.5))
|
||||||
|
plt.legend()
|
||||||
|
plt.savefig('diagrams/diagramallmonth.png')
|
||||||
|
mes = labels[0] + ' : +' + str(vals[0]) + '\n' + labels[1] + ' : -' + str(vals[1]) + '\n'
|
||||||
|
with open('diagrams/diagramallmonth.png', 'rb') as diagram:
|
||||||
|
bot.send_photo(message.chat.id, diagram)
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
|
||||||
|
|
||||||
|
def analysis_month_rm(message):
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.user == User.get(username=message.chat.id),
|
||||||
|
Transaction.month == datetime.datetime.now().strftime('%m'),
|
||||||
|
Transaction.type == 'consuption'
|
||||||
|
)
|
||||||
|
vals = []
|
||||||
|
labels = []
|
||||||
|
for i in transactions:
|
||||||
|
if have_in_vals(i.category, labels)[0]:
|
||||||
|
pos = have_in_vals(i.category, labels)[1]
|
||||||
|
vals[pos] += i.sum
|
||||||
|
else:
|
||||||
|
labels.append(i.category)
|
||||||
|
vals.append(i.sum)
|
||||||
|
|
||||||
|
exp = []
|
||||||
|
for _ in labels:
|
||||||
|
exp.append(0.1)
|
||||||
|
|
||||||
|
plt.pie(vals, labels=labels, explode=exp, wedgeprops=dict(width=0.5))
|
||||||
|
plt.legend()
|
||||||
|
plt.savefig('diagrams/rmanalysismonth.png')
|
||||||
|
|
||||||
|
mes = ''
|
||||||
|
pos = 0
|
||||||
|
for i in labels:
|
||||||
|
mes += i + ' : -' + str(vals[pos]) + currencyes.currensyes['ru-ruble'] + '\n'
|
||||||
|
pos += 1
|
||||||
|
|
||||||
|
with open('diagrams/rmanalysismonth.png', 'rb') as diagram:
|
||||||
|
bot.send_photo(message.chat.id, diagram)
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
|
||||||
|
|
||||||
|
def have_in_vals(category, labels):
|
||||||
|
pos = 0
|
||||||
|
for i in labels:
|
||||||
|
if i == category:
|
||||||
|
return True, pos
|
||||||
|
pos += 1
|
||||||
|
return False, pos
|
||||||
|
|
||||||
|
|
||||||
|
def analysis_month_add(message):
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.user == User.get(username=message.chat.id),
|
||||||
|
Transaction.month == datetime.datetime.now().strftime('%m'),
|
||||||
|
Transaction.type == 'incom'
|
||||||
|
)
|
||||||
|
vals = []
|
||||||
|
labels = []
|
||||||
|
for i in transactions:
|
||||||
|
if have_in_vals(i.category, labels)[0]:
|
||||||
|
pos = have_in_vals(i.category, labels)[1]
|
||||||
|
vals[pos] += i.sum
|
||||||
|
else:
|
||||||
|
labels.append(i.category)
|
||||||
|
vals.append(i.sum)
|
||||||
|
|
||||||
|
exp = []
|
||||||
|
for _ in labels:
|
||||||
|
exp.append(0.1)
|
||||||
|
|
||||||
|
plt.pie(vals, labels=labels, explode=exp, wedgeprops=dict(width=0.5))
|
||||||
|
plt.legend()
|
||||||
|
plt.savefig('diagrams/addanalysismonth.png')
|
||||||
|
|
||||||
|
mes = ''
|
||||||
|
pos = 0
|
||||||
|
for i in labels:
|
||||||
|
mes += i + ' : +' + str(vals[pos]) + currencyes.currensyes['ru-ruble'] + '\n'
|
||||||
|
pos += 1
|
||||||
|
|
||||||
|
with open('diagrams/addanalysismonth.png', 'rb') as diagram:
|
||||||
|
bot.send_photo(message.chat.id, diagram)
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
Binary file not shown.
+3
-1
@@ -26,7 +26,9 @@ class Transaction(BaseModel):
|
|||||||
type = CharField(column_name='TransactionType', max_length=10, null=False, default='incom')
|
type = CharField(column_name='TransactionType', max_length=10, null=False, default='incom')
|
||||||
sum = FloatField(column_name='TransactionSum', null=False, default=0)
|
sum = FloatField(column_name='TransactionSum', null=False, default=0)
|
||||||
user = ForeignKeyField(User, unique=False)
|
user = ForeignKeyField(User, unique=False)
|
||||||
date = DateField(column_name='Date', default=datetime.datetime.today())
|
year = CharField(column_name='Year', max_length=10, default=datetime.datetime.now().strftime("%Y"))
|
||||||
|
month = CharField(column_name='month', max_length=10, default=datetime.datetime.now().strftime('%m'))
|
||||||
|
day = CharField(column_name='day', max_length=10, default=datetime.datetime.now().strftime('%d'))
|
||||||
time = TimeField(column_name='time', default=datetime.datetime.now())
|
time = TimeField(column_name='time', default=datetime.datetime.now())
|
||||||
category = TextField(column_name='category', default='None category')
|
category = TextField(column_name='category', default='None category')
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
@@ -5,6 +5,8 @@ import locales
|
|||||||
from changelocale import change_locale
|
from changelocale import change_locale
|
||||||
from database.models import User, Transaction
|
from database.models import User, Transaction
|
||||||
from currencyes import currensyes
|
from currencyes import currensyes
|
||||||
|
from multiprocessing import Process
|
||||||
|
from analysismonth import analysis_month, analysis_month_rm, analysis_month_add
|
||||||
|
|
||||||
|
|
||||||
# функция ограничения количества знаков после запятой
|
# функция ограничения количества знаков после запятой
|
||||||
@@ -12,244 +14,258 @@ def to_fixed(num_obj, digits=0):
|
|||||||
return f"{num_obj:.{digits}f}"
|
return f"{num_obj:.{digits}f}"
|
||||||
|
|
||||||
|
|
||||||
# основной обработчик для бота
|
def main():
|
||||||
def main_bot(messages):
|
# основной обработчик для бота
|
||||||
for message in messages:
|
def main_bot(messages):
|
||||||
if message.text.split(' ')[0] == '/start' or message.text.split(' ')[0] == '/help':
|
for message in messages:
|
||||||
mes = None
|
if message.text.split(' ')[0] == '/start' or message.text.split(' ')[0] == '/help':
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = locales.ru['help_message']
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = locales.en['help_message']
|
|
||||||
_, user = User.get_or_create(username=message.chat.id)
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/ru' or message.text.split(' ')[0] == '/en':
|
|
||||||
change_locale(message) # функция для изменения языка
|
|
||||||
elif message.text.split(' ')[0] == '/balance':
|
|
||||||
user = User.get(username=message.chat.id)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Баланс: '
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Balance: '
|
|
||||||
mes += to_fixed(user.balance, 2) + currensyes['ru-ruble']
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/add' or message.text.split(' ')[0] == '+':
|
|
||||||
if len(message.text.split(' ')) < 2:
|
|
||||||
mes = None
|
mes = None
|
||||||
if locales.LOCALE == 'ru':
|
if locales.LOCALE == 'ru':
|
||||||
mes = locales.ru['erradd']
|
mes = locales.ru['help_message']
|
||||||
elif locales.LOCALE == 'en':
|
elif locales.LOCALE == 'en':
|
||||||
mes = locales.en['erradd']
|
mes = locales.en['help_message']
|
||||||
|
_, user = User.get_or_create(username=message.chat.id)
|
||||||
bot.send_message(message.chat.id, mes)
|
bot.send_message(message.chat.id, mes)
|
||||||
else:
|
elif message.text.split(' ')[0] == '/ru' or message.text.split(' ')[0] == '/en':
|
||||||
|
change_locale(message) # функция для изменения языка
|
||||||
|
elif message.text.split(' ')[0] == '/balance':
|
||||||
user = User.get(username=message.chat.id)
|
user = User.get(username=message.chat.id)
|
||||||
user.balance += float(message.text.split(' ')[1])
|
mes = ''
|
||||||
user.save()
|
|
||||||
if len(message.text.split(' ')) == 3:
|
|
||||||
Transaction.create(
|
|
||||||
sum=int(message.text.split(' ')[1]),
|
|
||||||
type='incom',
|
|
||||||
user=User.get(username=message.chat.id),
|
|
||||||
category=message.text.split(' ')[2]
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
Transaction.create(
|
|
||||||
sum=int(message.text.split(' ')[1]),
|
|
||||||
type='incom',
|
|
||||||
user=User.get(username=message.chat.id)
|
|
||||||
)
|
|
||||||
bot.send_message(message.chat.id, to_fixed(user.balance, 2) + currensyes['ru-ruble'])
|
|
||||||
elif message.text.split(' ')[0] == '/rm' or message.text.split(' ')[0] == '-':
|
|
||||||
if len(message.text.split(' ')) < 2:
|
|
||||||
mes = None
|
|
||||||
if locales.LOCALE == 'ru':
|
if locales.LOCALE == 'ru':
|
||||||
mes = locales.ru['errrm']
|
mes = 'Баланс: '
|
||||||
elif locales.LOCALE == 'en':
|
elif locales.LOCALE == 'en':
|
||||||
mes = locales.en['errrm']
|
mes = 'Balance: '
|
||||||
|
mes += to_fixed(user.balance, 2) + currensyes['ru-ruble']
|
||||||
bot.send_message(message.chat.id, mes)
|
bot.send_message(message.chat.id, mes)
|
||||||
else:
|
elif message.text.split(' ')[0] == '/add' or message.text.split(' ')[0] == '+':
|
||||||
user = User.get(username=message.chat.id)
|
if len(message.text.split(' ')) < 2:
|
||||||
user.balance -= float(message.text.split(' ')[1])
|
mes = None
|
||||||
user.save()
|
if locales.LOCALE == 'ru':
|
||||||
if len(message.text.split(' ')) == 3:
|
mes = locales.ru['erradd']
|
||||||
Transaction.create(
|
elif locales.LOCALE == 'en':
|
||||||
sum=int(message.text.split(' ')[1]),
|
mes = locales.en['erradd']
|
||||||
type='consuption',
|
bot.send_message(message.chat.id, mes)
|
||||||
user=User.get(username=message.chat.id),
|
|
||||||
category=message.text.split(' ')[2]
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
Transaction.create(
|
user = User.get(username=message.chat.id)
|
||||||
sum=int(message.text.split(' ')[1]),
|
user.balance += float(message.text.split(' ')[1])
|
||||||
type='consuption',
|
user.save()
|
||||||
user=User.get(username=message.chat.id)
|
if len(message.text.split(' ')) == 3:
|
||||||
)
|
Transaction.create(
|
||||||
bot.send_message(message.chat.id, to_fixed(user.balance, 2) + currensyes['ru-ruble'])
|
sum=int(message.text.split(' ')[1]),
|
||||||
elif message.text.split(' ')[0] == '/addtoday':
|
type='incom',
|
||||||
transactions = Transaction.select().where(
|
user=User.get(username=message.chat.id),
|
||||||
Transaction.type == 'incom',
|
category=message.text.split(' ')[2]
|
||||||
Transaction.date == datetime.datetime.today(),
|
)
|
||||||
Transaction.user == User.get(username=message.chat.id).id
|
else:
|
||||||
)
|
Transaction.create(
|
||||||
mes = ''
|
sum=int(message.text.split(' ')[1]),
|
||||||
if locales.LOCALE == 'ru':
|
type='incom',
|
||||||
mes = 'Ваши доходы за сегодня:\n\n'
|
user=User.get(username=message.chat.id)
|
||||||
elif locales.LOCALE == 'en':
|
)
|
||||||
mes = 'Your incomes today:\n\n'
|
bot.send_message(message.chat.id, to_fixed(user.balance, 2) + currensyes['ru-ruble'])
|
||||||
iteration = 1
|
elif message.text.split(' ')[0] == '/rm' or message.text.split(' ')[0] == '-':
|
||||||
if len(transactions) == 0:
|
if len(message.text.split(' ')) < 2:
|
||||||
|
mes = None
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = locales.ru['errrm']
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = locales.en['errrm']
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
else:
|
||||||
|
user = User.get(username=message.chat.id)
|
||||||
|
user.balance -= float(message.text.split(' ')[1])
|
||||||
|
user.save()
|
||||||
|
if len(message.text.split(' ')) == 3:
|
||||||
|
Transaction.create(
|
||||||
|
sum=int(message.text.split(' ')[1]),
|
||||||
|
type='consuption',
|
||||||
|
user=User.get(username=message.chat.id),
|
||||||
|
category=message.text.split(' ')[2]
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
Transaction.create(
|
||||||
|
sum=int(message.text.split(' ')[1]),
|
||||||
|
type='consuption',
|
||||||
|
user=User.get(username=message.chat.id)
|
||||||
|
)
|
||||||
|
bot.send_message(message.chat.id, to_fixed(user.balance, 2) + currensyes['ru-ruble'])
|
||||||
|
elif message.text.split(' ')[0] == '/addtoday':
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.type == 'incom',
|
||||||
|
Transaction.day == datetime.datetime.today().strftime('%d'),
|
||||||
|
Transaction.user == User.get(username=message.chat.id).id
|
||||||
|
)
|
||||||
|
mes = ''
|
||||||
if locales.LOCALE == 'ru':
|
if locales.LOCALE == 'ru':
|
||||||
mes += 'Нет доходов за сегодня'
|
mes = 'Ваши доходы за сегодня:\n\n'
|
||||||
elif locales.LOCALE == 'en':
|
elif locales.LOCALE == 'en':
|
||||||
mes += 'No incomes today'
|
mes = 'Your incomes today:\n\n'
|
||||||
for i in transactions:
|
iteration = 1
|
||||||
mes += '-------------------------------------\n'
|
if len(transactions) == 0:
|
||||||
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
if locales.LOCALE == 'ru':
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
mes += 'Нет доходов за сегодня\n'
|
||||||
iteration += 1
|
elif locales.LOCALE == 'en':
|
||||||
mes += '-------------------------------------\n'
|
mes += 'No incomes today\n'
|
||||||
bot.send_message(message.chat.id, mes)
|
for i in transactions:
|
||||||
elif message.text.split(' ')[0] == '/rmtoday':
|
|
||||||
transactions = Transaction.select().where(
|
|
||||||
Transaction.type == 'consuption',
|
|
||||||
Transaction.date == datetime.datetime.today(),
|
|
||||||
Transaction.user == User.get(username=message.chat.id).id
|
|
||||||
)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Ваши расходы за сегодня:\n\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Your consuptions today:\n\n'
|
|
||||||
iteration = 1
|
|
||||||
if len(transactions) == 0:
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes += 'Нет расходов за сегодня'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes += 'No consuptions today'
|
|
||||||
for i in transactions:
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
|
||||||
iteration += 1
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/rmall':
|
|
||||||
transactions = Transaction.select().where(
|
|
||||||
Transaction.type == 'consuption',
|
|
||||||
Transaction.user == User.get(username=message.chat.id).id
|
|
||||||
)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Ваши расходы за все время:\n\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Your all consuptions:\n\n'
|
|
||||||
iteration = 1
|
|
||||||
if len(transactions) == 0:
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes += 'Нет расходов за все время'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes += 'No consuptions for all time'
|
|
||||||
for i in transactions:
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
|
||||||
iteration += 1
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/addall':
|
|
||||||
transactions = Transaction.select().where(
|
|
||||||
Transaction.type == 'incom',
|
|
||||||
Transaction.user == User.get(username=message.chat.id).id
|
|
||||||
)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Ваши доходы за все время:\n\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Your all incomes:\n\n'
|
|
||||||
iteration = 1
|
|
||||||
if len(transactions) == 0:
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes += 'Нет доходов за все время'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes += 'No incomes for all time'
|
|
||||||
for i in transactions:
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
|
||||||
iteration += 1
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/rmmonth':
|
|
||||||
transactions = Transaction.select().where(
|
|
||||||
Transaction.user == User.get(username=message.chat.id),
|
|
||||||
Transaction.type == 'consuption'
|
|
||||||
)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Ваши расходы за этот месяц:\n\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Your consuptions for this month:\n\n'
|
|
||||||
iteration = 1
|
|
||||||
if len(transactions) == 0:
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes += 'Нет расходов за этот месяц\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes += 'No consuptions for this month\n'
|
|
||||||
|
|
||||||
for i in transactions:
|
|
||||||
if str(i.date).split('-')[1] == datetime.datetime.today().strftime('%m'):
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
|
||||||
iteration += 1
|
|
||||||
mes += '-------------------------------------\n'
|
|
||||||
bot.send_message(message.chat.id, mes)
|
|
||||||
elif message.text.split(' ')[0] == '/addmonth':
|
|
||||||
transactions = Transaction.select().where(
|
|
||||||
Transaction.user == User.get(username=message.chat.id),
|
|
||||||
Transaction.type == 'incom'
|
|
||||||
)
|
|
||||||
mes = ''
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes = 'Ваши доходы за этот месяц:\n\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes = 'Your incomes for this month:\n\n'
|
|
||||||
iteration = 1
|
|
||||||
if len(transactions) == 0:
|
|
||||||
if locales.LOCALE == 'ru':
|
|
||||||
mes += 'Нет доходов за этот месяц\n'
|
|
||||||
elif locales.LOCALE == 'en':
|
|
||||||
mes += 'No incomes for this month\n'
|
|
||||||
|
|
||||||
for i in transactions:
|
|
||||||
if str(i.date).split('-')[1] == datetime.datetime.today().strftime('%m'):
|
|
||||||
mes += '-------------------------------------\n'
|
mes += '-------------------------------------\n'
|
||||||
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
+ ' || ' + str(i.date) + ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
iteration += 1
|
iteration += 1
|
||||||
mes += '-------------------------------------\n'
|
mes += '-------------------------------------\n'
|
||||||
bot.send_message(message.chat.id, mes)
|
bot.send_message(message.chat.id, mes)
|
||||||
elif message.text.split(' ')[0] == '/analysismonth':
|
elif message.text.split(' ')[0] == '/rmtoday':
|
||||||
bot.send_message(message.chat.id, 'pass')
|
transactions = Transaction.select().where(
|
||||||
else:
|
Transaction.type == 'consuption',
|
||||||
mes = None
|
Transaction.day == datetime.datetime.today().strftime('%d'),
|
||||||
if locales.LOCALE == 'ru':
|
Transaction.user == User.get(username=message.chat.id).id
|
||||||
mes = locales.ru['error404_message']
|
)
|
||||||
elif locales.LOCALE == 'en':
|
mes = ''
|
||||||
mes = locales.en['error404_message']
|
if locales.LOCALE == 'ru':
|
||||||
bot.send_message(message.chat.id, mes)
|
mes = 'Ваши расходы за сегодня:\n\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = 'Your consuptions today:\n\n'
|
||||||
|
iteration = 1
|
||||||
|
if len(transactions) == 0:
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes += 'Нет расходов за сегодня\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes += 'No consuptions today\n'
|
||||||
|
for i in transactions:
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
|
iteration += 1
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
elif message.text.split(' ')[0] == '/rmall':
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.type == 'consuption',
|
||||||
|
Transaction.user == User.get(username=message.chat.id).id
|
||||||
|
)
|
||||||
|
mes = ''
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = 'Ваши расходы за все время:\n\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = 'Your all consuptions:\n\n'
|
||||||
|
iteration = 1
|
||||||
|
if len(transactions) == 0:
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes += 'Нет расходов за все время\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes += 'No consuptions for all time\n'
|
||||||
|
for i in transactions:
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
|
iteration += 1
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
elif message.text.split(' ')[0] == '/addall':
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.type == 'incom',
|
||||||
|
Transaction.user == User.get(username=message.chat.id).id
|
||||||
|
)
|
||||||
|
mes = ''
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = 'Ваши доходы за все время:\n\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = 'Your all incomes:\n\n'
|
||||||
|
iteration = 1
|
||||||
|
if len(transactions) == 0:
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes += 'Нет доходов за все время\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes += 'No incomes for all time\n'
|
||||||
|
for i in transactions:
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
|
iteration += 1
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
elif message.text.split(' ')[0] == '/rmmonth':
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.user == User.get(username=message.chat.id),
|
||||||
|
Transaction.month == datetime.datetime.now().strftime('%m'),
|
||||||
|
Transaction.type == 'consuption'
|
||||||
|
)
|
||||||
|
mes = ''
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = 'Ваши расходы за этот месяц:\n\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = 'Your consuptions for this month:\n\n'
|
||||||
|
iteration = 1
|
||||||
|
if len(transactions) == 0:
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes += 'Нет расходов за этот месяц\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes += 'No consuptions for this month\n'
|
||||||
|
|
||||||
|
for i in transactions:
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
mes += str(iteration) + ' || -' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
|
iteration += 1
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
elif message.text.split(' ')[0] == '/addmonth':
|
||||||
|
transactions = Transaction.select().where(
|
||||||
|
Transaction.user == User.get(username=message.chat.id),
|
||||||
|
Transaction.month == datetime.datetime.now().strftime('%m'),
|
||||||
|
Transaction.type == 'incom'
|
||||||
|
)
|
||||||
|
mes = ''
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = 'Ваши доходы за этот месяц:\n\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = 'Your incomes for this month:\n\n'
|
||||||
|
iteration = 1
|
||||||
|
if len(transactions) == 0:
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes += 'Нет доходов за этот месяц\n'
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes += 'No incomes for this month\n'
|
||||||
|
|
||||||
|
for i in transactions:
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
mes += str(iteration) + ' || +' + str(i.sum) + currensyes['ru-ruble'] + ' || ' + i.category \
|
||||||
|
+ ' || ' + str(i.day) + '-' + str(i.month) + '-' + str(i.year) \
|
||||||
|
+ ' || ' + i.time.strftime('%H:%M:%S') + ' ||\n'
|
||||||
|
iteration += 1
|
||||||
|
mes += '-------------------------------------\n'
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
elif message.text.split(' ')[0] == '/analysismonth':
|
||||||
|
Process(target=analysis_month, args=(message,)).start()
|
||||||
|
elif message.text.split(' ')[0] == '/rmanalysismonth':
|
||||||
|
Process(target=analysis_month_rm, args=(message, )).start()
|
||||||
|
elif message.text.split(' ')[0] == '/addanalysismonth':
|
||||||
|
Process(target=analysis_month_add, args=(message,)).start()
|
||||||
|
else:
|
||||||
|
mes = None
|
||||||
|
if locales.LOCALE == 'ru':
|
||||||
|
mes = locales.ru['error404_message']
|
||||||
|
elif locales.LOCALE == 'en':
|
||||||
|
mes = locales.en['error404_message']
|
||||||
|
bot.send_message(message.chat.id, mes)
|
||||||
|
|
||||||
|
bot.set_update_listener(main_bot)
|
||||||
|
|
||||||
|
try:
|
||||||
|
bot.polling(none_stop=True)
|
||||||
|
while True:
|
||||||
|
pass
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
cprint('\ngoodbye', 'green')
|
||||||
|
exit()
|
||||||
|
except Exception as e:
|
||||||
|
cprint(str(e), 'red')
|
||||||
|
bot.polling(none_stop=True)
|
||||||
|
|
||||||
|
|
||||||
bot.set_update_listener(main_bot)
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
try:
|
|
||||||
bot.polling(none_stop=True)
|
|
||||||
while True:
|
|
||||||
pass
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
cprint('\ngoodbye', 'green')
|
|
||||||
exit()
|
|
||||||
except Exception as e:
|
|
||||||
cprint(str(e), 'red')
|
|
||||||
bot.polling(none_stop=True)
|
|
||||||
Reference in new issue
Block a user