Spaces:
Sleeping
Sleeping
Upload keepalive.py with huggingface_hub
Browse files- keepalive.py +17 -32
keepalive.py
CHANGED
|
@@ -1,42 +1,27 @@
|
|
| 1 |
-
import os
|
| 2 |
import time
|
| 3 |
import random
|
| 4 |
-
import threading
|
| 5 |
import requests
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
while True:
|
| 9 |
try:
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
'Upgrade-Insecure-Requests': '1',
|
| 19 |
-
}
|
| 20 |
-
resp = requests.get(f'https://{host}/', headers=headers, timeout=15)
|
| 21 |
-
print(f'[HumanPing] {time.strftime("%H:%M:%S")} - Status: {resp.status_code}')
|
| 22 |
-
except Exception as e:
|
| 23 |
-
print(f'[HumanPing] Error: {e}')
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
print(f'[HumanPing] Next ping in {wait//60}m {wait%60}s')
|
| 28 |
time.sleep(wait)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
os.system('date > /tmp/last_activity')
|
| 34 |
-
os.system('whoami > /dev/null')
|
| 35 |
-
except:
|
| 36 |
-
pass
|
| 37 |
-
time.sleep(random.randint(300, 600))
|
| 38 |
-
|
| 39 |
-
threading.Thread(target=human_ping, daemon=True).start()
|
| 40 |
-
threading.Thread(target=activity_check, daemon=True).start()
|
| 41 |
|
| 42 |
-
print('[
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
import random
|
|
|
|
| 3 |
import requests
|
| 4 |
+
import threading
|
| 5 |
|
| 6 |
+
def ping(url, name):
|
| 7 |
while True:
|
| 8 |
try:
|
| 9 |
+
headers = {
|
| 10 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
|
| 11 |
+
'Accept': 'text/html',
|
| 12 |
+
}
|
| 13 |
+
resp = requests.get(url, headers=headers, timeout=15)
|
| 14 |
+
print(f'[{name}] {time.strftime("%H:%M:%S")} -> {resp.status_code}', flush=True)
|
| 15 |
+
except:
|
| 16 |
+
print(f'[{name}] Error', flush=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
wait = random.randint(900, 3600)
|
| 19 |
+
print(f'[{name}] Next {wait//60}m', flush=True)
|
|
|
|
| 20 |
time.sleep(wait)
|
| 21 |
|
| 22 |
+
# Ping keep-alive space back
|
| 23 |
+
threading.Thread(target=ping, args=('https://bjo53-keep-alive.hf.space/', 'KeepAlive'), daemon=True).start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
print('[Mutual] Started', flush=True)
|
| 26 |
+
while True:
|
| 27 |
+
time.sleep(60)
|