[Add] Added main func of container
This commit is contained in:
parent
93237ec7d2
commit
24af11f88a
@ -6,7 +6,8 @@ MAINTAINER Tan Jin (tjtanjin)
|
|||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# copy all the files to the container
|
# copy all the files to the container
|
||||||
COPY . .
|
COPY main.py .
|
||||||
|
COPY req.txt .
|
||||||
RUN mkdir ./images
|
RUN mkdir ./images
|
||||||
|
|
||||||
# install app-specific dependencies
|
# install app-specific dependencies
|
||||||
|
|||||||
17
docker-compose
Normal file
17
docker-compose
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
version: '3.9'
|
||||||
|
|
||||||
|
services:
|
||||||
|
|
||||||
|
telegram_bot_docker_tmpl:
|
||||||
|
container_name: MireaCheckBot
|
||||||
|
image: mirea_check_bot
|
||||||
|
|
||||||
|
build: .
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- BOT_TOKEN=${BOT_TOKEN}
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- ./logs:/~/TelegramBotDockerTmpl/logs
|
||||||
|
|
||||||
|
restart: on-failure
|
||||||
102
main.py
102
main.py
@ -1,7 +1,105 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
from health_ping import HealthPing
|
||||||
|
|
||||||
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update, constants
|
||||||
|
from telegram.ext import Application, CallbackQueryHandler, CommandHandler, ContextTypes
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
if os.getenv("HEALTHCHECKS_ENDPOINT"):
|
||||||
|
HealthPing(
|
||||||
|
url=os.getenv("HEALTHCHECKS_ENDPOINT"),
|
||||||
|
schedule="1 * * * *",
|
||||||
|
retries=[60, 300, 720],
|
||||||
|
).start()
|
||||||
|
|
||||||
|
hpo = 0
|
||||||
|
|
||||||
|
snils = "143-471-137-40"
|
||||||
|
place = 0
|
||||||
|
|
||||||
|
# Define a few command handlers. These usually take the two arguments update and
|
||||||
|
# context.
|
||||||
|
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
|
"""Sends a message with three inline buttons attached."""
|
||||||
|
await update.message.reply_text("Вы хуй, можете проверить списки!")
|
||||||
|
|
||||||
|
|
||||||
|
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
|
"""Send a message when the command /help is issued."""
|
||||||
|
await update.message.reply_text("Help!")
|
||||||
|
|
||||||
|
|
||||||
|
async def check_lists(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
|
"""Parses the CallbackQuery and updates the message text."""
|
||||||
|
query = update.callback_query
|
||||||
|
|
||||||
|
# CallbackQueries need to be answered, even if no notification to the user is needed
|
||||||
|
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
|
||||||
|
await query.answer()
|
||||||
|
|
||||||
|
await query.edit_message_text(text=f"Selected option: {query.data}")
|
||||||
|
|
||||||
|
|
||||||
|
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
|
"""Echo the user message."""
|
||||||
|
await update.message.reply_text(update.message.text)
|
||||||
|
|
||||||
|
|
||||||
|
async def check_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
|
global hpo, snils, place
|
||||||
|
|
||||||
|
response = requests.get(api_1)
|
||||||
|
|
||||||
|
if response.status_code == 200:
|
||||||
|
# Получение данных в формате JSON
|
||||||
|
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
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)
|
||||||
|
else:
|
||||||
|
await update.message.reply_text(f"Проверьте позже, в текущий момент сервис недоступен!")
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(f'Ошибка: {response.status_code}')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pass
|
"""
|
||||||
|
Handles the initial launch of the program (entry point).
|
||||||
|
"""
|
||||||
|
print(TOKEN[:10])
|
||||||
|
application = Application.builder().token(TOKEN).build()
|
||||||
|
|
||||||
|
# on different commands - answer in Telegram
|
||||||
|
application.add_handler(CommandHandler("start", start))
|
||||||
|
application.add_handler(CallbackQueryHandler(check_lists))
|
||||||
|
application.add_handler(CommandHandler("help", help_command))
|
||||||
|
application.add_handler(CommandHandler("check", check_command))
|
||||||
|
|
||||||
|
# Run the bot until the user presses Ctrl-C
|
||||||
|
application.run_polling(allowed_updates=Update.ALL_TYPES)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
26
req.txt
26
req.txt
@ -0,0 +1,26 @@
|
|||||||
|
aiofiles==23.2.1
|
||||||
|
aiohttp==3.9.5
|
||||||
|
aiosignal==1.3.1
|
||||||
|
annotated-types==0.7.0
|
||||||
|
anyio==4.4.0
|
||||||
|
attrs==23.2.0
|
||||||
|
certifi==2024.7.4
|
||||||
|
charset-normalizer==3.3.2
|
||||||
|
crontab==1.0.1
|
||||||
|
frozenlist==1.4.1
|
||||||
|
h11==0.14.0
|
||||||
|
health_ping==1.0.1
|
||||||
|
httpcore==1.0.5
|
||||||
|
httpx==0.27.0
|
||||||
|
idna==3.7
|
||||||
|
magic-filter==1.0.12
|
||||||
|
multidict==6.0.5
|
||||||
|
pydantic==2.8.2
|
||||||
|
pydantic_core==2.20.1
|
||||||
|
python-dotenv==1.0.1
|
||||||
|
python-telegram-bot==21.4
|
||||||
|
requests==2.32.3
|
||||||
|
sniffio==1.3.1
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
urllib3==2.2.2
|
||||||
|
yarl==1.9.4
|
||||||
Loading…
x
Reference in New Issue
Block a user