[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

27
main.py
View File

@ -5,6 +5,8 @@ from health_ping import HealthPing
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, constants
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes
from datetime import datetime
from tzlocal import get_localzone
import requests
@ -14,8 +16,9 @@ load_dotenv(dotenv_path)
TOKEN = os.getenv("BOT_TOKEN")
# CHAT = os.getenv("CHAT_ID")
api_1 = "https://priem.mirea.ru/competitions_api/entrants?competitions[]=1793877758295678262"
api_2 = "https://priem.mirea.ru/competitions_api/entrants?competitions[]=1793877924783332662"
apis = ["1793877758295678262", "1793877924783332662", "1793877644101557558", "1793877826603064630", "1793875716983495990"]
api_url = "https://priem.mirea.ru/competitions_api/entrants?competitions[]="
if os.getenv("HEALTHCHECKS_ENDPOINT"):
@ -34,7 +37,7 @@ place = 0
# context.
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""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:
@ -61,23 +64,29 @@ async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
async def check_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
global hpo, snils, place
response = requests.get(api_1)
for api in apis:
response = requests.get(api_url+api)
if response.status_code == 200:
# Получение данных в формате JSON
data = response.json()
data = response.json()["data"][0]
data = data["data"][0]["entrants"]
if len(data) != 0:
for entrant in data:
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"*Конкурс: Проектирование и обслуживание высоконагруженных информационных систем*\nВы на {place+1} месте по общему конкурсу, на {hpo+1} месте по высшему приоритеу, колво баллов {entrant['fm']}", parse_mode=constants.ParseMode.MARKDOWN_V2)
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

View File

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