Skip to content

Commit

Permalink
TG and spiders for prod
Browse files Browse the repository at this point in the history
  • Loading branch information
rsolovev-dev committed May 23, 2024
1 parent f5242a9 commit 7d52fa9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions runspiders-bot-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

if [ -f /home/ecodomen/ecodomen-dev/.env ]; then
export $(echo $(cat /home/ecodomen/ecodomen-prod/.env | sed 's/#.*//g'| xargs) | envsubst)
fi

source /home/ecodomen/ecodomen-prod/env/bin/activate
cd /home/ecodomen/ecodomen-prod/
python3 /home/ecodomen/ecodomen-prod/src/telegram_bot/__main__.py

deactivate
17 changes: 14 additions & 3 deletions src/telegram_bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@
import subprocess
import os

current_directory = os.getcwd()

TOKEN = os.environ["BOT_TOKEN"]
ERROR_LOGS_PATH = "logs/grabber_errors.log"
SPIDERS_SCRIPT_PATH = "compose/scrapy/scrapy-dev.sh"
CHAT_ID = os.environ["CHAT_ID"]
TOPIC_SUPPORT_ID = int(os.environ["TOPIC_SUPPORT_ID"]) # 1435
TOPIC_SUPPORT_ID = int(os.environ["TOPIC_SUPPORT_ID"])


if current_directory == '/home/ecodomen/ecodomen-dev/src/telegram_bot/':
SPIDERS_SCRIPT_PATH = "compose/scrapy/scrapy-dev.sh"
SERVER = "dev"
else:
SPIDERS_SCRIPT_PATH = "compose/scrapy/scrapy-prod.sh"
SERVER = "prod"



router = Router()
bot = Bot(TOKEN, parse_mode="markdown")
Expand All @@ -33,7 +44,7 @@ async def command_start_handler(*args, **kwargs) -> None:
await bot.send_message(
chat_id=CHAT_ID,
message_thread_id=TOPIC_SUPPORT_ID,
text="🕷️🕷️🕷️ Запуск спайдеров 🕷️🕷️🕷️"
text=f"🕷️🕷️🕷️ Запуск спайдеров - {SERVER} 🕷️🕷️🕷️"
)
try:
subprocess.run(["sh", f"{SPIDERS_SCRIPT_PATH}"], check=True)
Expand Down

0 comments on commit 7d52fa9

Please sign in to comment.