Skip to content

Commit 35710cb

Browse files
Psychosoc1alllirrikk
authored andcommitted
Исправление ошибок «чистого» запуска (#47)
* fix(OrioksHelper): semaphore length getting bug * chore(requirements): get rid of `install` requirement This line crashed requirements installing process (see below). No code is using the package, so removing the dependency looks acceptable. FYI: `install` is `pip-install` now, see: pypi/support#451 * chore(.gitignore): add `.vscode/` for better VS Code experience * refactor(OrioksHelper): get rid of not working users queue * refactor(UserHelper): silence `increment_failed_request_count` bug * fix(get_orioks_news): add users data clearing on error in `user_news_check_from_news_id` * build(requirements): support pip-compile, remove unnecessary requirements * refactor: apply `pylint` + `black`
1 parent d003990 commit 35710cb

File tree

6 files changed

+125
-107
lines changed

6 files changed

+125
-107
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
__pycache__/
22
venv/
33
.idea/
4+
.vscode/
45
setenv.sh
56
users_data/**/*.json
67
users_data/**/*.pkl

app/helpers/OrioksHelper.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010

1111
from app.exceptions import OrioksInvalidLoginCredentialsException
1212
from app.helpers import (
13-
TelegramMessageHelper,
1413
CommonHelper,
1514
UserHelper,
1615
)
17-
import aiogram.utils.markdown as md
1816

1917
from config import config
2018

@@ -27,29 +25,6 @@ async def orioks_login_save_cookies(
2725
user_login: int, user_password: str, user_telegram_id: int
2826
) -> None:
2927
# pylint: disable=protected-access
30-
user_queue = len(_sem._waiters) + 2
31-
if user_queue - 2 > 0:
32-
logging.info('login: %s', user_queue)
33-
_cats_queue_emoji = f'{"🐈" * (user_queue - 1)}🐈‍⬛'
34-
await TelegramMessageHelper.text_message_to_user(
35-
user_telegram_id=user_telegram_id,
36-
message=md.text(
37-
md.text(_cats_queue_emoji),
38-
md.text(
39-
md.text(
40-
f'Твой номер в очереди на авторизацию: {user_queue}.'
41-
),
42-
md.text(
43-
'Ты получишь уведомление, когда она будет выполнена.'
44-
),
45-
sep=' ',
46-
),
47-
md.text(
48-
'Это предотвращает слишком большую нагрузку на ОРИОКС'
49-
),
50-
sep='\n',
51-
),
52-
)
5328
async with _sem:
5429
async with ClientSession(
5530
timeout=config.REQUESTS_TIMEOUT,

app/helpers/UserHelper.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from aiogram.utils import markdown
2-
31
from app.exceptions import DatabaseException
42
from app.models.users import UserStatus, UserNotifySettings
5-
from config import config
63

74

85
class UserHelper:
@@ -126,32 +123,8 @@ def get_users_with_enabled_news_subscription():
126123
return users
127124

128125
@staticmethod
129-
async def increment_failed_request_count(user_telegram_id: int) -> None:
130-
user = UserHelper.__get_user_by_telegram_id(
131-
user_telegram_id=user_telegram_id
132-
)
133-
user.failed_request_count += 1
134-
if user.failed_request_count > config.ORIOKS_MAX_FAILED_REQUESTS:
135-
from app.helpers import OrioksHelper
136-
from app.helpers import TelegramMessageHelper
137-
138-
OrioksHelper.make_orioks_logout(user_telegram_id=user_telegram_id)
139-
await TelegramMessageHelper.text_message_to_user(
140-
user_telegram_id=user_telegram_id,
141-
message=markdown.text(
142-
markdown.hbold('Ваш аккаунт был деавторизирован.'),
143-
markdown.text(
144-
'🔧 Ошибки при получении данных с сервера ОРИОКС.'
145-
),
146-
markdown.text('Пожалуйста, авторизуйтесь заново: /login'),
147-
markdown.text(),
148-
markdown.text(
149-
'Связаться с поддержкой Бота: @orioks_monitoring_support_bot'
150-
),
151-
sep='\n',
152-
),
153-
)
154-
user.save()
126+
async def increment_failed_request_count(_: int) -> None:
127+
return # FIXME
155128

156129
@staticmethod
157130
def reset_failed_request_count(user_telegram_id: int) -> None:

checking/news/get_orioks_news.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ async def user_news_check_from_news_id(
172172
message=f'[{user_telegram_id}] - old_json["last_id"] > last_news_id["last_id"]'
173173
)
174174
await session.close()
175+
CommonHelper.safe_delete(path=path_users_to_file)
175176
raise Exception(
176177
f'[{user_telegram_id}] - old_json["last_id"] > last_news_id["last_id"]'
177178
)

requirements.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
aiofiles==0.8.0
2+
aiogram==2.19
3+
aioschedule==0.5.2
4+
alembic==1.8.0
5+
beautifulsoup4==4.10.0
6+
Mako==1.2.0
7+
mypy==0.960
8+
Pillow==9.1.0
9+
pylint-runner==0.6.0
10+
pylint==2.14.1
11+
python-dotenv==0.20.0
12+
qrcode==7.3.1
13+
requests==2.27.1
14+
SQLAlchemy==1.4.37
15+
types-aiofiles==0.8.8

requirements.txt

Lines changed: 106 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,120 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile
6+
#
17
aiofiles==0.8.0
8+
# via -r requirements.in
29
aiogram==2.19
3-
aiohttp==3.8.1
10+
# via -r requirements.in
11+
aiohttp==3.8.6
12+
# via aiogram
413
aioschedule==0.5.2
5-
aiosignal==1.2.0
14+
# via -r requirements.in
15+
aiosignal==1.3.2
16+
# via aiohttp
617
alembic==1.8.0
7-
anyio==3.5.0
8-
astroid==2.11.5
9-
async-generator==1.10
10-
async-timeout==4.0.2
11-
attrs==21.4.0
12-
Babel==2.9.1
18+
# via -r requirements.in
19+
astroid==2.11.7
20+
# via pylint
21+
async-timeout==4.0.3
22+
# via aiohttp
23+
attrs==24.3.0
24+
# via aiohttp
25+
babel==2.9.1
26+
# via aiogram
1327
beautifulsoup4==4.10.0
14-
certifi==2021.10.8
15-
cffi==1.15.0
28+
# via -r requirements.in
29+
certifi==2024.12.14
30+
# via
31+
# aiogram
32+
# requests
1633
charset-normalizer==2.0.12
17-
colorama==0.4.4
18-
cryptography==36.0.1
19-
dill==0.3.5.1
20-
frozenlist==1.3.0
21-
greenlet==1.1.2
22-
h11==0.12.0
23-
html2image==2.0.1
24-
httpcore==0.14.7
25-
httpx==0.22.0
26-
idna==3.3
27-
imgkit==1.2.2
28-
importlib-metadata==4.11.4
29-
importlib-resources==5.7.1
30-
install==1.3.5
31-
isort==5.10.1
32-
lazy-object-proxy==1.7.1
33-
Mako==1.2.0
34-
MarkupSafe==2.1.1
34+
# via
35+
# aiohttp
36+
# requests
37+
colorama==0.4.6
38+
# via
39+
# pylint
40+
# pylint-runner
41+
# qrcode
42+
dill==0.3.9
43+
# via pylint
44+
frozenlist==1.5.0
45+
# via
46+
# aiohttp
47+
# aiosignal
48+
greenlet==3.1.1
49+
# via sqlalchemy
50+
idna==3.10
51+
# via
52+
# requests
53+
# yarl
54+
isort==5.13.2
55+
# via pylint
56+
lazy-object-proxy==1.10.0
57+
# via astroid
58+
mako==1.2.0
59+
# via
60+
# -r requirements.in
61+
# alembic
62+
markupsafe==3.0.2
63+
# via mako
3564
mccabe==0.7.0
36-
multidict==6.0.2
65+
# via pylint
66+
multidict==6.1.0
67+
# via
68+
# aiohttp
69+
# yarl
3770
mypy==0.960
38-
mypy-extensions==0.4.3
39-
outcome==1.1.0
40-
Pillow==9.1.0
41-
platformdirs==2.5.2
42-
pycparser==2.21
71+
# via -r requirements.in
72+
mypy-extensions==1.0.0
73+
# via mypy
74+
pillow==9.1.0
75+
# via -r requirements.in
76+
platformdirs==4.3.6
77+
# via pylint
78+
propcache==0.2.1
79+
# via yarl
4380
pylint==2.14.1
81+
# via
82+
# -r requirements.in
83+
# pylint-runner
4484
pylint-runner==0.6.0
45-
pyOpenSSL==22.0.0
46-
PySocks==1.7.1
85+
# via -r requirements.in
4786
python-dotenv==0.20.0
48-
pytz==2021.3
87+
# via -r requirements.in
88+
pytz==2024.2
89+
# via babel
4990
qrcode==7.3.1
91+
# via -r requirements.in
5092
requests==2.27.1
51-
rfc3986==1.5.0
52-
six==1.16.0
53-
sniffio==1.2.0
54-
sortedcontainers==2.4.0
55-
soupsieve==2.3.1
56-
SQLAlchemy==1.4.37
57-
tomli==2.0.1
58-
tomlkit==0.11.0
59-
trio==0.20.0
60-
trio-websocket==0.9.2
93+
# via -r requirements.in
94+
soupsieve==2.6
95+
# via beautifulsoup4
96+
sqlalchemy==1.4.37
97+
# via
98+
# -r requirements.in
99+
# alembic
100+
tomli==2.2.1
101+
# via
102+
# mypy
103+
# pylint
104+
tomlkit==0.13.2
105+
# via pylint
61106
types-aiofiles==0.8.8
62-
typing_extensions==4.2.0
63-
urllib3==1.26.8
64-
wrapt==1.14.1
65-
wsproto==1.1.0
66-
yarl==1.7.2
67-
zipp==3.8.0
107+
# via -r requirements.in
108+
typing-extensions==4.12.2
109+
# via
110+
# multidict
111+
# mypy
112+
urllib3==1.26.20
113+
# via requests
114+
wrapt==1.17.2
115+
# via astroid
116+
yarl==1.18.3
117+
# via aiohttp
118+
119+
# The following packages are considered to be unsafe in a requirements file:
120+
# setuptools

0 commit comments

Comments
 (0)