mirror of
https://github.com/Alexander-D-Karpov/scripts.git
synced 2024-11-10 15:26:34 +03:00
minor election status fixes
This commit is contained in:
parent
762c9ae286
commit
783bd23798
|
@ -1,10 +1,18 @@
|
|||
FROM python:3.9-slim
|
||||
ARG PYTHON_VERSION=3.11-slim
|
||||
FROM python:${PYTHON_VERSION} as python
|
||||
|
||||
|
||||
FROM python as python-build-stage
|
||||
|
||||
ARG BUILD_ENVIRONMENT=local
|
||||
RUN mkdir "/app"
|
||||
WORKDIR /app
|
||||
ARG BUILD_ENVIRONMENT=local
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
ADD requirements.txt requirements.txt
|
||||
ADD main.py main.py
|
||||
ADD subscribed_chats.json subscribed_chats.json
|
||||
|
||||
COPY bot.py .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["python", "main.py"]
|
|
@ -1,6 +1,7 @@
|
|||
import asyncio
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from os import getenv
|
||||
|
||||
from aiogram import Bot, Dispatcher, html, F
|
||||
|
@ -293,6 +294,8 @@ async def unsubscribe_callback(callback: CallbackQuery):
|
|||
|
||||
@dp.message(Command("get_data"))
|
||||
async def get_data_handler(message: Message):
|
||||
global subjects_data
|
||||
|
||||
chat_id = str(message.chat.id)
|
||||
if chat_id not in subscribed_chats or not subscribed_chats[chat_id]:
|
||||
await message.answer(
|
||||
|
@ -303,6 +306,9 @@ async def get_data_handler(message: Message):
|
|||
limits_data = await get_itmo_limits()
|
||||
response = "Информация о выбранных вариантах:\n\n"
|
||||
|
||||
if not subjects_data:
|
||||
subjects_data = await get_itmo_data()
|
||||
|
||||
for item_id in subscribed_chats[chat_id]:
|
||||
item = next(
|
||||
(
|
||||
|
@ -368,23 +374,38 @@ async def update_token_handler(message: Message) -> None:
|
|||
global ITMO_TOKEN
|
||||
ITMO_TOKEN = new_token
|
||||
|
||||
with open(".env", "r") as file:
|
||||
lines = file.readlines()
|
||||
with open(".env", "w") as file:
|
||||
for line in lines:
|
||||
if line.startswith("ITMO_TOKEN="):
|
||||
file.write(f"ITMO_TOKEN={new_token}\n")
|
||||
else:
|
||||
file.write(line)
|
||||
if not new_token:
|
||||
await message.answer("Пожалуйста, укажите новый токен после команды.")
|
||||
return
|
||||
|
||||
if os.path.exists(".env"):
|
||||
with open(".env", "r") as file:
|
||||
lines = file.readlines()
|
||||
with open(".env", "w") as file:
|
||||
for line in lines:
|
||||
if line.startswith("ITMO_TOKEN="):
|
||||
file.write(f"ITMO_TOKEN={new_token}\n")
|
||||
else:
|
||||
file.write(line)
|
||||
|
||||
await message.answer("Токен успешно обновлен.")
|
||||
|
||||
|
||||
async def periodic_updates(bot: Bot):
|
||||
global subjects_data
|
||||
|
||||
while True:
|
||||
limits_data = await get_itmo_limits()
|
||||
if not limits_data:
|
||||
logging.error("Ошибка при получении лимитов")
|
||||
await asyncio.sleep(300)
|
||||
continue
|
||||
for chat_id, subscribed_items in subscribed_chats.items():
|
||||
response = "Обновленная информация о выбранных вариантах:\n\n"
|
||||
|
||||
if not subjects_data:
|
||||
subjects_data = await get_itmo_data()
|
||||
|
||||
for item_id in subscribed_items:
|
||||
item = next(
|
||||
(
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
aiogram==3.10.0
|
||||
python-dotenv==1.0.1
|
||||
httpx==0.27.2
|
||||
aiohttp==3.9.5
|
Loading…
Reference in New Issue
Block a user