From ea1d710223ad717d8f7ae47d30bd83ec862161c4 Mon Sep 17 00:00:00 2001 From: Hamlet Date: Tue, 27 Aug 2024 10:20:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 3 +++ CHANGELOG.md | 1 + src/base/user_input/add_new_market_item.py | 8 ++++---- src/helpers/utils.py | 6 +++--- tools/send_release_notification.py | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bace195..906d8d8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,9 +7,12 @@ repos: language: system types: [python] pass_filenames: false + exclude: "src/*test*.py" - id: format name: format entry: make format language: system types: [python] pass_filenames: false + exclude: "src/*test*.py" + diff --git a/CHANGELOG.md b/CHANGELOG.md index f5a72b3..31e3c65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Функции действий для игрока (прогулка, работа, и тд) из `base/player.py` перенесены в `base/actions.py` - Рефакторинг файла `config.py` +- Модуль `requests` окончательно заменен на `httpx` ## [5.1.0] - 2024-08-16 diff --git a/src/base/user_input/add_new_market_item.py b/src/base/user_input/add_new_market_item.py index 653567a..4775eae 100644 --- a/src/base/user_input/add_new_market_item.py +++ b/src/base/user_input/add_new_market_item.py @@ -44,7 +44,7 @@ def name_state(call: CallbackQuery): ) return - with bot.retrieve_data(call.from_user.id, call.message.chat.id) as data: + with bot.retrieve_data(call.from_user.id, call.message.chat.id) as data: # type: ignore data["name"] = item.name user = database.users.get(id=call.from_user.id) @@ -79,14 +79,14 @@ def invalid_int_input(message: Message): @bot.message_handler(state=AddNewItemState.quantity, is_digit=True) def quantity_state(message: Message): user = database.users.get(id=from_user(message).id) - with bot.retrieve_data(from_user(message).id, message.chat.id) as data: + with bot.retrieve_data(from_user(message).id, message.chat.id) as data: # type: ignore user_item = database.items.get(owner=user._id, name=data["name"]) if user_item.quantity < int(message.text): # type: ignore bot.reply_to(message, "У тебя нет столько") return - with bot.retrieve_data(from_user(message).id, message.chat.id) as data: + with bot.retrieve_data(from_user(message).id, message.chat.id) as data: # type: ignore data["quantity"] = int(message.text) # type: ignore call_message_id = redis_cache.get(f"{from_user(message).id}_item_add_message") @@ -106,7 +106,7 @@ def quantity_state(message: Message): @bot.message_handler(state=AddNewItemState.price, is_digit=True) def price_state(message: Message): user = database.users.get(id=from_user(message).id) - with bot.retrieve_data(from_user(message).id, message.chat.id) as data: + with bot.retrieve_data(from_user(message).id, message.chat.id) as data: # type: ignore try: user_item = database.items.get(owner=user._id, name=data["name"]) except NoResult: diff --git a/src/helpers/utils.py b/src/helpers/utils.py index cf1952f..6d9e560 100644 --- a/src/helpers/utils.py +++ b/src/helpers/utils.py @@ -6,7 +6,7 @@ from typing_extensions import deprecated -import requests +import httpx from semver import Version from telebot.types import Message, ReplyParameters, InlineKeyboardButton, User from telebot.util import antiflood, escape, split_string, quick_markup @@ -210,9 +210,9 @@ def send_channel_subscribe_message(message: Message): def check_version() -> str: # type: ignore url = "https://api.github.com/repos/HamletSargsyan/livebot/releases/latest" - response = requests.get(url) + response = httpx.get(url) - if not response.ok: + if response.status_code != 200: logger.error(response.text) response.raise_for_status() diff --git a/tools/send_release_notification.py b/tools/send_release_notification.py index f8fb8e8..846d5ea 100644 --- a/tools/send_release_notification.py +++ b/tools/send_release_notification.py @@ -1,6 +1,6 @@ import os from typing import Any, NoReturn, Union -import requests +import httpx from telebot import TeleBot from telebot.util import quick_markup @@ -8,7 +8,7 @@ def get_github_release_info(version) -> Union[dict[Any, Any], NoReturn]: url = f"https://api.github.com/repos/HamletSargsyan/livebot/releases/tags/{version}" - response = requests.get(url) + response = httpx.get(url) response.raise_for_status() release_info = response.json() # type: dict