hotfix: log any update and use index for excels
All checks were successful
Build and Run VSTU Public TG bot / build_and_run (push) Successful in 27s

This commit is contained in:
2026-04-13 23:10:54 +03:00
parent 8bbb440bce
commit 7495bd949b
7 changed files with 91 additions and 19 deletions

39
main.py
View File

@@ -22,12 +22,22 @@ import keyboards as kb
import re
import fnmatch
from middleware import LoggingMiddleware
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
# --- Настройки ---
engine = create_async_engine(os.getenv("DATABASE_URL"))
async_session = async_sessionmaker(engine, expire_on_commit=False)
data_mgr = DataManager(os.getenv("FACULTETS_JSON_URL"), os.getenv("GROUPS_JSON_URL"))
data_mgr = DataManager(os.getenv("FACULTETS_JSON_URL"), os.getenv("GROUPS_JSON_URL"), os.getenv("PARSER_JSON_URL"))
bot = None
dp = Dispatcher()
@@ -203,16 +213,17 @@ async def view_group(callback: types.CallbackQuery):
# Просмотр файла
@dp.callback_query(F.data.startswith("view_excel:"))
async def view_excel(callback: types.CallbackQuery):
pre_uniq_path = callback.data.split(":")[1]
uniqpath = "vstu.ru/rasp?dep=" + pre_uniq_path
pre_index = callback.data.split(":")[1]
# Находим имя файла для красоты
h_name = "Excel файл"
for g in data_mgr.groups.values():
for ex in g.get('excels', []):
if ex.get('uniqpath', "") == uniqpath: h_name = ex['display_filename']; break
try:
ex = data_mgr.parser['all_files'][int(pre_index)]
h_name = ex['display_filename']
except Exception as e:
print(f"safe?: {e}")
builder = InlineKeyboardBuilder()
builder.row(types.InlineKeyboardButton(text="🔔 Подписаться на файл", callback_data=f"suco:excel:{pre_uniq_path}"))
builder.row(types.InlineKeyboardButton(text="🔔 Подписаться на файл", callback_data=f"suco:excel:{pre_index}"))
builder.row(types.InlineKeyboardButton(text="⬅️ Назад", callback_data="menu_start"))
await callback.message.edit_text(f"📄 Файл: *{h_name}*", reply_markup=builder.as_markup(), parse_mode="Markdown")
@@ -224,11 +235,13 @@ async def sub_confirm(callback: types.CallbackQuery):
sub_value = val
if mode == "excel":
pre_uniq_path = h_name
uniqpath = "vstu.ru/rasp?dep=" + pre_uniq_path
excel = data_mgr.get_excel_by_uniqpath(uniqpath)
sub_value = excel['url'].split("/")[-1]
h_name = sub_value
pre_index = h_name
try:
excel = data_mgr.parser['all_files'][int(pre_index)]
sub_value = excel['url'].split("/")[-1]
h_name = sub_value
except Exception as e:
print(f"safe? e={e}")
async with async_session() as session:
# Регистрация пользователя если нет
@@ -337,6 +350,8 @@ async def main():
await conn.run_sync(Base.metadata.create_all)
await data_mgr.refresh_cache(connector)
dp.update.middleware(LoggingMiddleware()) # <-- добавьте эту строку
asyncio.create_task(start_rabbitmq_consumer())
# Периодическое обновление индексов