Spaces:
Running
Running
| import time | |
| import random | |
| import requests | |
| import threading | |
| def ping(url, name): | |
| while True: | |
| try: | |
| headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36', | |
| 'Accept': 'text/html', | |
| } | |
| resp = requests.get(url, headers=headers, timeout=15) | |
| print(f'[{name}] {time.strftime("%H:%M:%S")} -> {resp.status_code}', flush=True) | |
| except: | |
| print(f'[{name}] Error', flush=True) | |
| wait = random.randint(900, 3600) | |
| print(f'[{name}] Next {wait//60}m', flush=True) | |
| time.sleep(wait) | |
| # Ping keep-alive space back | |
| threading.Thread(target=ping, args=('https://bjo53-keep-alive.hf.space/', 'KeepAlive'), daemon=True).start() | |
| print('[Mutual] Started', flush=True) | |
| while True: | |
| time.sleep(60) | |