[Add] Added new messages

This commit is contained in:
Maxim Romanko 2024-08-02 11:40:10 +03:00
parent d03368bcb5
commit dec5035ffc
2 changed files with 35 additions and 25 deletions

57
main.py
View File

@ -5,6 +5,8 @@ from health_ping import HealthPing
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, constants from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, constants
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes
from datetime import datetime
from tzlocal import get_localzone
import requests import requests
@ -14,8 +16,9 @@ load_dotenv(dotenv_path)
TOKEN = os.getenv("BOT_TOKEN") TOKEN = os.getenv("BOT_TOKEN")
# CHAT = os.getenv("CHAT_ID") # CHAT = os.getenv("CHAT_ID")
api_1 = "https://priem.mirea.ru/competitions_api/entrants?competitions[]=1793877758295678262" apis = ["1793877758295678262", "1793877924783332662", "1793877644101557558", "1793877826603064630", "1793875716983495990"]
api_2 = "https://priem.mirea.ru/competitions_api/entrants?competitions[]=1793877924783332662"
api_url = "https://priem.mirea.ru/competitions_api/entrants?competitions[]="
if os.getenv("HEALTHCHECKS_ENDPOINT"): if os.getenv("HEALTHCHECKS_ENDPOINT"):
@ -34,7 +37,7 @@ place = 0
# context. # context.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""Sends a message with three inline buttons attached.""" """Sends a message with three inline buttons attached."""
await update.message.reply_text("Вы хуй, можете проверить списки!") await update.message.reply_text("Чтобы проверить списки отправьте /check")
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
@ -61,31 +64,37 @@ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
async def check_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def check_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
global hpo, snils, place global hpo, snils, place
response = requests.get(api_1) for api in apis:
if response.status_code == 200: response = requests.get(api_url+api)
# Получение данных в формате JSON
data = response.json() if response.status_code == 200:
# Получение данных в формате JSON
data = response.json()["data"][0]
entrants_data = data["entrants"]
if len(entrants_data) != 0:
for entrant in entrants_data:
if entrant["spn"] != snils:
if "iHPO" in entrant.keys():
hpo += 1
if entrant["s"] == "Активный" or entrant["s"] == "Сданы ВИ":
place += 1
else:
await update.message.reply_text(f"""*Конкурс: {data['title']}*
Бюджетных мест: {data['plan']}
Вы на {place+1} месте по общему конкурсу, на {hpo+1} месте по высшему приоритеу, баллы: {entrant['fm']}
Приоритет: {entrant['p']}
Обновлено: {datetime.fromisoformat(data['updated_at']).astimezone(get_localzone()).strftime("%d.%m %H:%M")}""", parse_mode=constants.ParseMode.MARKDOWN_V2)
break
place = 0
hpo = 0
else:
await update.message.reply_text(f"Проверьте позже, в текущий момент сервис недоступен!")
data = data["data"][0]["entrants"]
if len(data) != 0:
for entrant in data:
if entrant["spn"] != snils:
if "iHPO" in entrant.keys():
hpo += 1
if entrant["s"] == "Активный" or entrant["s"] == "Сданы ВИ":
place += 1
else:
await update.message.reply_text(f"*Конкурс: Проектирование и обслуживание высоконагруженных информационных систем*\nВы на {place+1} месте по общему конкурсу, на {hpo+1} месте по высшему приоритеу, колво баллов {entrant['fm']}", parse_mode=constants.ParseMode.MARKDOWN_V2)
break
place = 0
hpo = 0
else: else:
await update.message.reply_text(f"Проверьте позже, в текущий момент сервис недоступен!") print(f'Ошибка: {response.status_code}')
else:
print(f'Ошибка: {response.status_code}')
def main(): def main():
""" """

View File

@ -24,3 +24,4 @@ sniffio==1.3.1
typing_extensions==4.12.2 typing_extensions==4.12.2
urllib3==2.2.2 urllib3==2.2.2
yarl==1.9.4 yarl==1.9.4
tzlocal