Datasets:
Download Version2_Context/2/keep_alive.py from ysn-rfd/text-dataset-tiny-code-script-py-format: direct link, hf CLI and curl.
- Browser
- Download file 820 Bytes
-
https://huggingface.co/datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/resolve/main/Version2_Context/2/keep_alive.py
- Command line
-
hf download hf://datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/Version2_Context/2/keep_alive.py
-
curl -L -o keep_alive.py https://huggingface.co/datasets/ysn-rfd/text-dataset-tiny-code-script-py-format/resolve/main/Version2_Context/2/keep_alive.py
820 Bytes
| import requests | |
| import threading | |
| import time | |
| def ping_service(): | |
| """ارسال درخواست پینگ به سرویس برای نگه داشتن آن فعال.""" | |
| url = "https://render-telegram-bot-2-bmin.onrender.com" | |
| while True: | |
| try: | |
| requests.get(url) | |
| print(f"Pinged {url} to keep service alive") | |
| except Exception as e: | |
| print(f"Error pinging service: {e}") | |
| # هر 14 دقیقه یک بار پینگ بزن (زیر 15 دقیقه برای جلوگیری از خاموشی) | |
| time.sleep(5 * 60) | |
| # شروع ترد پینگ در پسزمینه | |
| def start_keep_alive(): | |
| """شروع سرویس نگه داشتن ربات فعال.""" | |
| thread = threading.Thread(target=ping_service) | |
| thread.daemon = True | |
| thread.start() | |