Skip to content

Commit 6bdfd47

Browse files
committed
PEP8: break long lines, add final newlines, update pylint config for tests
1 parent a7212e0 commit 6bdfd47

File tree

11 files changed

+52
-26
lines changed

11 files changed

+52
-26
lines changed

.pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ ignore=venv,.venv
55
[MESSAGES CONTROL]
66
# Disable warnings about missing docstrings
77
disable=missing-module-docstring,
8-
missing-function-docstring
8+
missing-function-docstring,
9+
too-few-public-methods,
10+
missing-final-newline
911

1012
[FORMAT]
1113
# Max line length

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# Проверка наличия токенов
1818
if not TOKEN:
1919
print("[ERROR] BOT_TOKEN is not set in environment variables.", file=sys.stderr)
20-
exit(1)
20+
sys.exit(1)
2121

2222
# Настройка логирования
2323
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()

handlers/planner.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ async def handle_topic(message: types.Message, state: FSMContext):
5454
# Send plan to chat
5555
plan_text = "\n".join(plan)
5656
if len(plan_text) > 4000:
57-
plan_text = plan_text[:4000] + "...\n(The plan is too long, the full version will be in the file)"
57+
plan_text = plan_text[:4000] + "...\n(The plan is too long, the full version will \
58+
be in the file)"
5859

5960
await message.answer(f"📚 Your study plan:\n\n{plan_text}")
6061

@@ -64,11 +65,21 @@ async def handle_topic(message: types.Message, state: FSMContext):
6465
"In which format do you want to save the plan?",
6566
reply_markup=types.InlineKeyboardMarkup(
6667
inline_keyboard=[
67-
[types.InlineKeyboardButton(text="📄 pdf", callback_data="format_pdf"),
68-
types.InlineKeyboardButton(text="📄 txt", callback_data="format_txt")],
69-
[types.InlineKeyboardButton(text="🔄 Skip", callback_data="format_skip")]
68+
[
69+
types.InlineKeyboardButton(
70+
text="📄 pdf", callback_data="format_pdf"
71+
),
72+
types.InlineKeyboardButton(
73+
text="📄 txt", callback_data="format_txt"
74+
),
75+
],
76+
[
77+
types.InlineKeyboardButton(
78+
text="🔄 Skip", callback_data="format_skip"
79+
)
80+
],
7081
]
71-
)
82+
),
7283
)
7384

7485

@@ -90,11 +101,14 @@ async def process_format(callback: types.CallbackQuery, state: FSMContext):
90101
caption="📘 Your study plan in PDF"
91102
)
92103
else:
93-
txt_path = await save_plan_to_txt(plan, callback.from_user.id if callback.from_user else 0)
104+
txt_path = await save_plan_to_txt(
105+
plan, callback.from_user.id if callback.from_user else 0)
94106
if isinstance(callback.message, Message):
95107
await callback.message.answer_document(
96108
document=types.FSInputFile(txt_path),
97-
caption="📄 Your study plan in TXT"
109+
caption=(
110+
"📚 Your saved study plan"
111+
),
98112
)
99113
if isinstance(callback.message, Message):
100114
await show_next_actions(callback.message, state)
@@ -131,7 +145,9 @@ async def handle_reminders(callback: types.CallbackQuery, state: FSMContext):
131145
await callback.message.answer("Plan not found. Try creating a new one.")
132146
return
133147
# Start reminder scheduling
134-
message = await callback.message.answer("⏳ Scheduling reminders...") if isinstance(callback.message, Message) else None
148+
message = await callback.message.answer("⏳ Scheduling reminders...") if isinstance(
149+
callback.message, Message
150+
) else None
135151
# Run async reminder scheduling task
136152
reminders_count = await schedule_reminders(user_id, plan)
137153
# Update message after scheduling completion
@@ -153,7 +169,8 @@ async def handle_new_plan(callback: types.CallbackQuery, state: FSMContext):
153169
async def handle_goodbye(callback: types.CallbackQuery, state: FSMContext):
154170
await callback.answer()
155171
if isinstance(callback.message, Message):
156-
await callback.message.edit_text("Have a nice day! 👋 I'll be happy to help again when you need it.")
172+
await callback.message.edit_text("Have a nice day! 👋 I'll be happy to help \
173+
again when you need it.")
157174
await state.clear()
158175

159176

@@ -173,4 +190,6 @@ async def cmd_my_plans(message: types.Message):
173190
await message.answer_document(document=types.FSInputFile(txt_path),
174191
caption="📚 Your saved study plan")
175192
else:
176-
await message.answer(f"📚 Your saved study plan:\n\n{plan_text}")
193+
await message.answer(
194+
f"📚 Your saved study plan:\n\n{plan_text}"
195+
)

services/llm.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ async def generate_study_plan(topic: str) -> list:
3939
"""Generate a study plan using OpenAI API or fallback to local generation"""
4040
# Check if OpenAI API key is set and client is initialized
4141
if not OPENAI_API_KEY or client is None:
42-
logger.warning("OpenAI API key is missing or OpenAI client is not initialized, using local generator")
42+
logger.warning("OpenAI API key is missing or OpenAI client is not initialized, \
43+
using local generator")
4344
return generate_local_plan(topic)
4445

4546
for attempt in range(MAX_RETRIES):
@@ -50,9 +51,15 @@ async def generate_study_plan(topic: str) -> list:
5051

5152
response = client.chat.completions.create(
5253
model="gpt-3.5-turbo",
53-
messages=[{"role": "user",
54-
"content": f"Create a detailed study plan for the topic: {topic}. "
55-
f"Split the plan into 5-7 steps."}]
54+
messages=[
55+
{
56+
"role": "user",
57+
"content": (
58+
f"Create a detailed study plan for the topic: {topic}. "
59+
f"Split the plan into 5-7 steps."
60+
),
61+
}
62+
],
5663
)
5764

5865
text = response.choices[0].message.content

services/txt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
2-
import aiofiles
32
import logging
3+
import aiofiles
44

55
logger = logging.getLogger(__name__)
66

@@ -13,6 +13,6 @@ async def save_plan_to_txt(plan_lines: list[str], user_id: int) -> str:
1313
for line in plan_lines:
1414
await f.write(line + "\n")
1515
except Exception as e:
16-
logger.error(f"Failed to write TXT file: {e}")
16+
logger.error("Failed to write TXT file: %s", e)
1717
raise
1818
return filename

tests/test_db.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import os
22
import tempfile
3-
import pytest
4-
from services.db import save_user_plan, get_user_plan
53
from tinydb import TinyDB
4+
from services.db import save_user_plan, get_user_plan
65

76
def test_save_and_get_user_plan(monkeypatch):
87
with tempfile.NamedTemporaryFile(delete=False) as tmp:

tests/test_llm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import asyncio
32
from services.llm import generate_local_plan, generate_study_plan
43

54
@pytest.mark.parametrize("topic", ["Python", "Math", "History"])

tests/test_pdf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import tempfile
32
from services.pdf import save_plan_to_pdf
43

54
def test_save_plan_to_pdf(tmp_path):

tests/test_reminders.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import asyncio
32
from services.reminders import schedule_reminders
43

54
@pytest.mark.asyncio

tests/test_start_handler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import pytest
2-
from aiogram.types import Message
32
from handlers.start import start_handler
43

54
class DummyBot:
6-
async def send_message(self, chat_id, text, **kwargs):
5+
"""Dummy bot for testing purposes."""
6+
def __init__(self):
7+
self.last_message = None
8+
async def send_message(self, chat_id, text):
79
self.last_message = (chat_id, text)
810
return None
911

1012
class DummyMessage:
13+
"""Dummy message for testing purposes."""
1114
def __init__(self):
1215
self.text = "/start"
1316
self.chat = type("Chat", (), {"id": 1})()

0 commit comments

Comments
 (0)