Skip to content

Commit 4486573

Browse files
committed
Re-add health_checker.py
1 parent 5706211 commit 4486573

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

health_checker.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import datetime
4+
5+
TARGET_URL = "https://cosmo-classifier.onrender.com/"
6+
7+
def health_checker(target_url=TARGET_URL):
8+
timestamp = datetime.datetime.now(datetime.timezone.utc).isoformat()
9+
try:
10+
response = requests.get(target_url,timeout=10)
11+
soup = BeautifulSoup(response.text,"html.parser")
12+
title = soup.find("title").text if soup.find("title") else "NO TITLE"
13+
14+
print(f"[{timestamp}] Status:{response.status_code} | Title:'{title}' | Time elapsed:{response.elapsed.total_seconds():.2f}s")
15+
return {"status":response.status_code, "title":title, "ok":True, "error":None}
16+
except Exception as e:
17+
print(f"[{timestamp}] ERROR: {str(e)}")
18+
return {"status":None, "title": None, "ok":False, "error":str(e)}
19+
20+
if __name__ == "__main__":
21+
health_checker()

0 commit comments

Comments
 (0)