From 5fe8734185c55725a36c23d4688010a3e147692e Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:06:12 +0400 Subject: [PATCH 1/8] making it docker deployable --- Dockerfile | 22 ++++++++++++++++++++++ cron.txt | 1 + run.sh | 4 ++++ 3 files changed, 27 insertions(+) create mode 100644 Dockerfile create mode 100644 cron.txt create mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9113d6e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.10-slim + +WORKDIR /app + +COPY . /app + +RUN pip install --upgrade pip && \ + pip install python-decouple pytz telethon cryptg + +COPY run.sh /app/run.sh + +RUN chmod +x /app/run.sh + +COPY cron.txt /etc/cron.d/cron.txt + +RUN chmod 0644 /etc/cron.d/cron.txt + +RUN crontab /etc/cron.d/cron.txt + +RUN touch /var/log/cron.log + +CMD cron && tail -f /var/log/cron.log diff --git a/cron.txt b/cron.txt new file mode 100644 index 0000000..7c12d9d --- /dev/null +++ b/cron.txt @@ -0,0 +1 @@ +*/5 * * * * /app/run.sh >> /var/log/cron.log 2>&1 diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..47396c3 --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# Run the Python script +python3 main.py From 58f201464ba657bbabba873f13df739408229b7d Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:29:07 +0400 Subject: [PATCH 2/8] changing image install cron --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9113d6e..7a34fdc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM python:3.10-slim +FROM debian:bullseye-slim + +RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/* WORKDIR /app From 69c7f914daa28779f2a095b95860f758ee4aa098 Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:31:29 +0400 Subject: [PATCH 3/8] forgot pip --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7a34fdc..5e0ce13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ FROM debian:bullseye-slim -RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y cron python3-pip && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY . /app -RUN pip install --upgrade pip && \ - pip install python-decouple pytz telethon cryptg +RUN pip3 install --upgrade pip && \ + pip3 install python-decouple pytz telethon cryptg COPY run.sh /app/run.sh From 29240c1be0ce24694347a7bc71ba7fe09f8fe6eb Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:41:50 +0400 Subject: [PATCH 4/8] cron -f --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 5e0ce13..1a23f49 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,4 +21,4 @@ RUN crontab /etc/cron.d/cron.txt RUN touch /var/log/cron.log -CMD cron && tail -f /var/log/cron.log +CMD ["cron", "-f"] From fe9e8067f8e3b8aae1d108f79c6a36d7efdd35b8 Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:52:01 +0400 Subject: [PATCH 5/8] different approach removed cron added INTERVAL variable for async sleep --- Dockerfile | 22 ++++------------------ cron.txt | 1 - main.py | 12 +++++++++++- run.sh | 4 ---- 4 files changed, 15 insertions(+), 24 deletions(-) delete mode 100644 cron.txt delete mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile index 1a23f49..a698df9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,10 @@ -FROM debian:bullseye-slim - -RUN apt-get update && apt-get install -y cron python3-pip && rm -rf /var/lib/apt/lists/* +FROM python:3.10-slim WORKDIR /app COPY . /app -RUN pip3 install --upgrade pip && \ - pip3 install python-decouple pytz telethon cryptg - -COPY run.sh /app/run.sh - -RUN chmod +x /app/run.sh - -COPY cron.txt /etc/cron.d/cron.txt - -RUN chmod 0644 /etc/cron.d/cron.txt - -RUN crontab /etc/cron.d/cron.txt - -RUN touch /var/log/cron.log +RUN pip install --upgrade pip && \ + pip install python-decouple pytz telethon cryptg -CMD ["cron", "-f"] +CMD ["python3", "main.py"] diff --git a/cron.txt b/cron.txt deleted file mode 100644 index 7c12d9d..0000000 --- a/cron.txt +++ /dev/null @@ -1 +0,0 @@ -*/5 * * * * /app/run.sh >> /var/log/cron.log 2>&1 diff --git a/main.py b/main.py index 4521c81..e7d3d1b 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import asyncio from asyncio import sleep from logging import basicConfig, INFO, getLogger from time import time @@ -23,6 +24,7 @@ MESSAGE_ID = config("MESSAGE_ID", cast=int) CHANNEL_NAME = config("CHANNEL_NAME", default="FZX Paradox") TIME_ZONE = config("TIME_ZONE", default="Asia/Kolkata") + INTERVAL = config("INTERVAL", 300) # Time interval in seconds between checks except BaseException as ex: log.info(ex) exit(1) @@ -135,4 +137,12 @@ async def check_bots(): return -client.loop.run_until_complete(check_bots()) +async def main(): + while True: + log.info("Running periodic check...") + await check_bots() + log.info(f"Sleeping for {INTERVAL} seconds...") + await asyncio.sleep(INTERVAL) + +if __name__ == "__main__": + client.loop.run_until_complete(main()) diff --git a/run.sh b/run.sh deleted file mode 100644 index 47396c3..0000000 --- a/run.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -# Run the Python script -python3 main.py From 4860db425b46781eadb2d4a0bd77eea3be52e1ac Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:52:50 +0400 Subject: [PATCH 6/8] typo --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index e7d3d1b..7791d18 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import asyncio from asyncio import sleep from logging import basicConfig, INFO, getLogger from time import time @@ -142,7 +141,7 @@ async def main(): log.info("Running periodic check...") await check_bots() log.info(f"Sleeping for {INTERVAL} seconds...") - await asyncio.sleep(INTERVAL) + await sleep(INTERVAL) if __name__ == "__main__": client.loop.run_until_complete(main()) From 95ee030de18476ec0a399d21641da154f0dc17c1 Mon Sep 17 00:00:00 2001 From: HYBRID <48980248+hybridvamp@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:00:21 +0400 Subject: [PATCH 7/8] rem yml --- .github/workflows/status_updater.yml | 36 ---------------------------- 1 file changed, 36 deletions(-) delete mode 100644 .github/workflows/status_updater.yml diff --git a/.github/workflows/status_updater.yml b/.github/workflows/status_updater.yml deleted file mode 100644 index 88403bd..0000000 --- a/.github/workflows/status_updater.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Bot Status Check - -on: - schedule: - - cron: "*/5 * * * *" - workflow_dispatch: - -jobs: - update: - runs-on: ubuntu-latest - steps: - - name: Initial Checkout - uses: actions/checkout@v4 - - name: Set Up Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - name: Clone the Repo - uses: actions/checkout@master - with: - repository: ${{ secrets.REPO_NAME }} - - name: Install Dependencies - run: | - pip install --upgrade pip - pip install python-decouple pytz telethon cryptg - - name: Run the UserClient - run: | - python3 main.py - env: - APP_ID: ${{ secrets.APP_ID }} - API_HASH: ${{ secrets.API_HASH }} - BOTS: ${{ secrets.BOTS }} - HOSTS: ${{ secrets.HOSTS }} - SESSION: ${{ secrets.SESSION }} - CHANNEL_ID: ${{ secrets.CHANNEL_ID }} - MESSAGE_ID: ${{ secrets.MESSAGE_ID }} From 01d9a9905bb70d4a18f25fc192bb4d4a3a589e45 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Fri, 22 Dec 2023 07:01:12 +0000 Subject: [PATCH 8/8] 'Refactored by Sourcery' --- main.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 7791d18..aaf6b31 100644 --- a/main.py +++ b/main.py @@ -58,10 +58,14 @@ async def check_bots(): """ try: - await client.edit_message(CHANNEL_ID, MESSAGE_ID, status_message + f"""**Status Update Stats:** + await client.edit_message( + CHANNEL_ID, + MESSAGE_ID, + f"""{status_message}**Status Update Stats:** ┌ **Bots Verified :** 0 out of {len(BOTS)} ├ **Progress :** [○○○○○○○○○○] 0% -└ **Time Elasped :** 0s""") +└ **Time Elasped :** 0s""", + ) except BaseException as e: log.warning("[EDIT] Unable to edit message in the channel!") log.error(e) @@ -88,38 +92,44 @@ async def check_bots(): bot_stats[bot] = {"response_time": f"`{round(resp_time * 1000, 2)}ms`", "status": "✅", "host": host or "Unknown"} except BaseException: bot_stats[bot] = {"response_time": None, "status": "❌", "host": host or "Unknown"} - + await client.send_read_acknowledge(bot) log.info(f"[CHECK] Checked @{bot} - {bot_stats[bot]['status']}.") bot_no += 1 - - await client.edit_message(CHANNEL_ID, MESSAGE_ID, status_message + f"""**Status Update Stats:** + + await client.edit_message( + CHANNEL_ID, + MESSAGE_ID, + f"""{status_message}**Status Update Stats:** ┌ **Bots Verified :** {bot_no} out of {len(BOTS)} ├ **Progress :** {progress_bar(bot_no, len(BOTS))} -└ **Time Elasped :** {round(time() - start_time, 2)}s""") +└ **Time Elasped :** {round(time() - start_time, 2)}s""", + ) end_time = time() log.info("[CHECK] Completed periodic checks.") - status_message = header_msg + f"• **Avaliable Bots :** {avl_bots} out of {len(BOTS)}\n\n" - for bot, value in bot_stats.items(): - if bot_stats[bot]["response_time"] is None: - status_message += f"""┌ **Bot :** @{bot} + status_message = ( + f"{header_msg}• **Avaliable Bots :** {avl_bots} out of {len(BOTS)}\n\n" + ) + for bot in bot_stats: + status_message += ( + f"""┌ **Bot :** @{bot} ├ **Status :** {bot_stats[bot]['status']} └ **Host :** {bot_stats[bot]['host']} """ - else: - status_message += f"""┌ **Bot :** @{bot} + if bot_stats[bot]["response_time"] is None + else f"""┌ **Bot :** @{bot} ├ **Ping :** {bot_stats[bot]['response_time']} ├ **Status :** {bot_stats[bot]['status']} └ **Host :** {bot_stats[bot]['host']} """ - + ) total_time = end_time - start_time status_message += f"• **Last Periodic Checked in {round(total_time, 2)}s**\n\n" - + current_time = datetime.now(utc).astimezone(timezone(TIME_ZONE)) status_message += f"""• **Last Check Details :** ┌ **Time :** `{current_time.strftime('%H:%M:%S')} hrs`