Skip to content

Commit

Permalink
Merge pull request #3 from Nighty3098/InDevelopment
Browse files Browse the repository at this point in the history
In development
  • Loading branch information
Nighty3098 authored Mar 6, 2024
2 parents 2325898 + e1f2fc0 commit 409c8f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
31 changes: 16 additions & 15 deletions db.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,32 @@ async def today(user_id):
connection = sqlite3.connect(f"data/finances_{user_id}_{month_name}_{now_year}.db")
cursor = connection.cursor()

cursor.execute("SELECT SUM(value) FROM income WHERE date = ?", (current_date))
cursor.execute("SELECT SUM(value) FROM income WHERE date = ?", (current_date,))
income = cursor.fetchall()

cursor.execute("SELECT SUM(value) FROM consumption WHERE date = ?", (current_date))
cursor.execute("SELECT SUM(value) FROM consumption WHERE date = ?", (current_date,))
consumption = cursor.fetchall()

cursor.close()
connection.close()

result = " + " + str(income) + " руб\n" + " - " + str(consumption) + "руб"

return result

result = f"Статистика за {current_date}\n+ {str(income[0][0])} руб.\n- {str(consumption[0][0])} руб."
except sqlite3.OperationalError as err:
logger.error(err)
except sqlite3.ProgrammingError as err:
except sqlite3.ProgrammingError as err:
logger.error(err)
except sqlite3.AttributeError as err:
except AttributeError as err:
logger.error(err)

return "Отсутствуют данные"

result = f"{monthes[i]: Отсутствуют данные}\n"
return result

async def get_year_summary(user_id):
message = " "

for i in range(1, 13):
year_income = 0
year_consumption = 0

for i in range(12):
try:
connection = sqlite3.connect(
f"data/finances_{user_id}_{monthes[i]}_{now_year}.db"
Expand All @@ -180,17 +179,19 @@ async def get_year_summary(user_id):
cursor.execute("SELECT SUM(value) FROM consumption")
total_consumption = cursor.fetchall()

message += f"{monthes[i]}: +{total_income} руб\n -{total_consumption} руб\n"
message += f"\n{monthes[i]}:\n+ {str(total_income[0][0])} руб.\n- {str(total_consumption[0][0])} руб."

cursor.close()
connection.close()

except sqlite3.OperationalError as err:
logger.error(err)
except sqlite3.ProgrammingError as err:
logger.error(err)
except sqlite3.AttributeError as err:
except AttributeError as err:
logger.error(err)
message += f"{monthes[i]: Отсутствуют данные}\n"

# message = f"Статистика за {now_year} год: \n + {year_income} руб.\n - {year_consumption} руб."

return message
11 changes: 4 additions & 7 deletions handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,19 @@ async def today_summarize(message: Message):
try:
result = await today(user_id)

await message.answer(f"Статистика за сегодня:\n{result}")
# await message.edit_text(f"Статистика за сегодня:\nВаши расходы: {consumption} руб\nВаши доходы: {income} руб", reply_markup=await back_kb())
# logger.debug(f"User: {user_id}, summarize: -{consumption} +{income}")
await message.answer(result, reply_markup=await back_main())

logger.debug(f"User: {user_id}, summarize: {result}")
except AttributeError as err:
await message.answer("Отстутствуют данные в одной из таблиц", reply_markup=await back_kb())
await message.answer("Отстутствуют данные в одной из таблиц", reply_markup=await back_main())
logger.error(err)


@dp.message(Command("year"))
async def get_year_summary(message: Message):
async def year_summary(message: Message):
result = await get_year_summary(user_id)
await message.answer(result, reply_markup=await back_kb())



@dp.callback_query(F.data == "Back")
async def to_main_menu(call: CallbackQuery):
# await call.message.answer(HELLO_MESSAGE)
Expand Down

0 comments on commit 409c8f7

Please sign in to comment.