From 71fb626c1430f2036ae0b26f8e6876d847df5c3a Mon Sep 17 00:00:00 2001 From: zayac Date: Sun, 21 Apr 2024 14:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86docker=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 19 ++++++++++++++ requirements.txt | 43 ++++++++++++++++++++++++++++---- src/change_url/change_url_bot.py | 13 ++++++---- 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ecfdf8a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# 使用官方 Python 3.11 镜像 +FROM python:3.11 + +# 将应用代码复制到 /app 目录下 +COPY src/change_url /app +COPY requirements.txt /app/requirements.txt + +# 设置工作目录 +WORKDIR /app + +# 安装 Python 依赖 +RUN pip install -r requirements.txt + +# 设置容器启动时执行的命令 +CMD ["python", "change_url_bot.py"] + +# 设置健康检查 +HEALTHCHECK --interval=30s --timeout=30s --retries=3 \ + CMD pgrep -f change_url_bot.py || exit 1 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 144729d..ca871c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,49 @@ aiohttp==3.9.1 +aiosignal==1.3.1 +altgraph==0.17.4 +annotated-types==0.6.0 +anyio==4.3.0 +attrs==23.2.0 cachetools==5.3.2 +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +fastapi==0.110.1 +frozenlist==1.4.1 +greenlet==3.0.1 +h11==0.14.0 +idna==3.6 +Jinja2==3.1.3 loguru==0.7.2 +MarkupSafe==2.1.5 +multidict==6.0.5 +mysql-connector-python==8.3.0 +packaging==24.0 +pefile==2023.2.7 pika==1.3.2 playwright==1.40.0 +pydantic==2.7.0 +pydantic_core==2.18.1 +pyee==11.0.1 +pyinstaller==6.5.0 +pyinstaller-hooks-contrib==2024.3 PyQt6==6.6.1 -PyQt6_sip==13.6.0 +PyQt6-Qt6==6.6.2 +PyQt6-sip==13.6.0 pyTelegramBotAPI==4.15.2 -python_dateutil==2.8.2 -qdarkstyle==3.2.3 -qtpy==2.4.1 +python-dateutil==2.8.2 +pywin32-ctypes==0.2.2 +QDarkStyle==3.2.3 +QtPy==2.4.1 requests==2.31.0 schedule==1.2.1 +six==1.16.0 +sniffio==1.3.1 SQLAlchemy==2.0.25 +starlette==0.37.2 typing_extensions==4.9.0 -mysql-connector-python==8.3.0 \ No newline at end of file +urllib3==2.2.1 +uvicorn==0.29.0 +win32-setctime==1.1.0 +yarl==1.9.4 diff --git a/src/change_url/change_url_bot.py b/src/change_url/change_url_bot.py index df7a2ef..38ebf1b 100644 --- a/src/change_url/change_url_bot.py +++ b/src/change_url/change_url_bot.py @@ -1,12 +1,16 @@ import telebot import requests import time +import os from loguru import logger -from src.change_url.change_url import change_url +BOT_TOKEN = os.getenv('BOT_TOKEN', default="6356456493:AAF2J03isyhlOFF6WgoovRCzuvHheTrTKmM") +API_URL = os.getenv('API_URL', default="http://127.0.0.1:8080/changeurl") -TOKEN = '6356456493:AAF2J03isyhlOFF6WgoovRCzuvHheTrTKmM' -bot = telebot.TeleBot(TOKEN) +logger.debug(f"bot_token:{BOT_TOKEN}") +logger.debug(f"api_url:{API_URL}") + +bot = telebot.TeleBot(BOT_TOKEN) ky = ['技术客服域名值班'] hth = ['YYZBH②拒绝私聊', '3-信息同步频道'] @@ -35,7 +39,7 @@ def handle_forwarded_message(message): # user_info = message.forward_origin # response = f"这是一条转发的消息。{user_info}" try: - res = requests.post("http://127.0.0.1:8080/changeurl", params={'text': message.text}) + res = requests.post(API_URL, json={'text': message.text}) if res.status_code == 200: if res.json()['res']: msg = f'{res.json()["msg"]}修改成功' @@ -62,4 +66,3 @@ def start_polling(): if __name__ == "__main__": start_polling() # 开始长轮询 -