Spaces:
Running
Running
File size: 1,653 Bytes
bebe233 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # ============================================================
# PhishGuard AI - keep_alive.py
# Keeps your Render.com server awake 24/7.
#
# From architecture doc 5.3:
# Render free tier sleeps after 15 min of inactivity.
# This pings GET /health every 14 min to prevent that.
#
# WHERE TO RUN:
# - On a second laptop / old computer
# - On your phone using Termux (free Android app)
# - On a friend's computer
# - On your own laptop in a separate terminal (less ideal)
#
# HOW TO RUN:
# python keep_alive.py
# (keep this terminal window open — never close it)
# ============================================================
import time
import requests
import datetime
# !! CHANGE THIS to your actual Render URL !!
API_URL = "https://YOUR-APP-NAME.onrender.com/health"
INTERVAL = 14 * 60 # 14 minutes in seconds
print("=" * 50)
print("PhishGuard Keep-Alive Script")
print("=" * 50)
print(f"Pinging: {API_URL}")
print(f"Every: 14 minutes")
print(f"Started: {datetime.datetime.now():%Y-%m-%d %H:%M:%S}")
print("\nDO NOT close this window!")
print("Press Ctrl+C to stop.\n")
ping_count = 0
while True:
try:
r = requests.get(API_URL, timeout=15)
ping_count += 1
status = "OK" if r.status_code == 200 else f"ERROR {r.status_code}"
print(f"[{datetime.datetime.now():%H:%M:%S}] Ping #{ping_count} → {status}")
except requests.exceptions.ConnectionError:
print(f"[{datetime.datetime.now():%H:%M:%S}] Connection failed — server might be waking up...")
except Exception as e:
print(f"[{datetime.datetime.now():%H:%M:%S}] Error: {e}")
time.sleep(INTERVAL)
|