Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyarolf committed Sep 22, 2024
1 parent 8d9c6b2 commit cdfb9c0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
DB_NAME = os.environ.get("DB_NAME")
PAGE_ENTRIES = int(os.environ.get("PAGE_ENTRIES"))
LANGUAGE = os.environ.get("LANGUAGE")
MULTIBOT = os.environ.get("MULTIBOT", False) == 'true'
MULTIBOT = os.environ.get("MULTIBOT", False) == 'true'
4 changes: 1 addition & 3 deletions crypto_api/CryptoApiManager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

import grequests


Expand Down Expand Up @@ -42,7 +40,7 @@ async def get_top_ups(self):
return balances

@staticmethod
async def get_crypto_prices() -> dict[Any, float]:
async def get_crypto_prices() -> dict[str, float]:
usd_crypto_prices = {}
urls = {
"btc": 'https://api.kraken.com/0/public/Ticker?pair=BTCUSDT',
Expand Down
49 changes: 25 additions & 24 deletions handlers/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from utils.other_sql import OtherSQLQuery
from aiogram.exceptions import TelegramForbiddenError


class AdminCallback(CallbackData, prefix="admin"):
level: int
action: str
Expand Down Expand Up @@ -200,6 +201,19 @@ async def send_restocking_message(callback: CallbackQuery):
reply_markup=AdminConstants.confirmation_builder.as_markup())


async def delete_category(callback: CallbackQuery):
unpacked_callback = AdminCallback.unpack(callback.data)
delete_category_builder = await create_delete_entity_buttons(CategoryService.get_all_categories(
unpacked_callback.page),
"category")
delete_category_builder = await add_pagination_buttons(delete_category_builder, callback.data,
CategoryService.get_maximum_page(), AdminCallback.unpack,
AdminConstants.back_to_main_button)
await callback.message.edit_text(text=Localizator.get_text_from_key("admin_delete_category_msg"),
parse_mode=ParseMode.HTML,
reply_markup=delete_category_builder.as_markup())


async def create_delete_entity_buttons(get_all_entities_function,
entity_name):
entities = get_all_entities_function
Expand All @@ -214,23 +228,11 @@ async def create_delete_entity_buttons(get_all_entities_function,
return delete_entity_builder


async def delete_category(callback: CallbackQuery):
unpacked_callback = AdminCallback.unpack(callback.data)
delete_category_builder = await create_delete_entity_buttons(CategoryService.get_all_categories(
unpacked_callback.page),
"category")
delete_category_builder = await add_pagination_buttons(delete_category_builder, callback.data,
CategoryService.get_maximum_page(), AdminCallback.unpack,
AdminConstants.back_to_main_button)
await callback.message.edit_text(text=Localizator.get_text_from_key("admin_delete_category_msg"),
parse_mode=ParseMode.HTML,
reply_markup=delete_category_builder.as_markup())


async def delete_subcategory(callback: CallbackQuery):
unpacked_callback = AdminCallback.unpack(callback.data)
delete_subcategory_builder = await create_delete_entity_buttons(SubcategoryService.get_all(unpacked_callback.page),
"subcategory")
delete_subcategory_builder = await create_delete_entity_buttons(
SubcategoryService.get_all(unpacked_callback.page),
"subcategory")
delete_subcategory_builder = await add_pagination_buttons(delete_subcategory_builder, callback.data,
SubcategoryService.get_maximum_page(),
AdminCallback.unpack,
Expand Down Expand Up @@ -446,13 +448,6 @@ async def get_statistics(callback: CallbackQuery):
parse_mode=ParseMode.HTML)


async def send_db_file(callback: CallbackQuery):
with open(f"./data/{config.DB_NAME}", "rb") as f:
await callback.message.bot.send_document(callback.from_user.id,
types.BufferedInputFile(file=f.read(), filename="database.db"))
await callback.answer()


async def make_refund(callback: CallbackQuery):
unpacked_callback = AdminCallback.unpack(callback.data)
buy_id = int(unpacked_callback.args_to_action)
Expand All @@ -471,14 +466,20 @@ async def make_refund(callback: CallbackQuery):
subcategory=refund_data.subcategory),
parse_mode=ParseMode.HTML)
else:
await callback.message.edit_text(
text=Localizator.get_text_from_key("admin_successfully_refunded_with_tgid").format(
await callback.message.edit_text(text=Localizator.get_text_from_key("admin_successfully_refunded_with_tgid").format(
total_price=refund_data.total_price,
telegram_id=refund_data.telegram_id,
quantity=refund_data.quantity,
subcategory=refund_data.subcategory), parse_mode=ParseMode.HTML)


async def send_db_file(callback: CallbackQuery):
with open(f"./data/{config.DB_NAME}", "rb") as f:
await callback.message.bot.send_document(callback.from_user.id,
types.BufferedInputFile(file=f.read(), filename="database.db"))
await callback.answer()


@admin_router.callback_query(AdminIdFilter(), AdminCallback.filter())
async def admin_menu_navigation(callback: CallbackQuery, state: FSMContext, callback_data: AdminCallback):
current_level = callback_data.level
Expand Down
3 changes: 2 additions & 1 deletion handlers/user/all_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ async def show_subcategories_in_category(callback: CallbackQuery):
ItemService.get_maximum_page(unpacked_callback.category_id),
AllCategoriesCallback.unpack,
back_button)
await callback.message.edit_text(Localizator.get_text_from_key("admin_delete_subcategory_msg"), reply_markup=subcategory_buttons.as_markup(),
await callback.message.edit_text(Localizator.get_text_from_key("admin_delete_subcategory_msg"),
reply_markup=subcategory_buttons.as_markup(),
parse_mode=ParseMode.HTML)


Expand Down
10 changes: 5 additions & 5 deletions handlers/user/my_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def create_callback_profile(level: int, action: str = "", args_for_action="", pa
return MyProfileCallback(level=level, action=action, args_for_action=args_for_action, page=page).pack()


class MyProfileConstants:
back_to_main_menu = types.InlineKeyboardButton(text=Localizator.get_text_from_key("back_to_my_profile"),
callback_data=create_callback_profile(level=0))


@my_profile_router.message(F.text == Localizator.get_text_from_key("my_profile"), IsUserExistFilter())
async def my_profile_text_message(message: types.message):
await my_profile(message)


class MyProfileConstants:
back_to_main_menu = types.InlineKeyboardButton(text=Localizator.get_text_from_key("back_to_my_profile"),
callback_data=create_callback_profile(level=0))


async def get_my_profile_message(telegram_id: int):
user = UserService.get_by_tgid(telegram_id)
btc_balance = user.btc_balance
Expand Down

0 comments on commit cdfb9c0

Please sign in to comment.