main.py (834B)
1 from fastapi import FastAPI, HTTPException 2 import os 3 import requests 4 5 app = FastAPI(title="Service Status App") 6 7 STATUS_URL = os.getenv("STATUS_URL", "https://www.githubstatus.com/api/v2/status.json") 8 9 10 @app.get("/") 11 def root(): 12 return {"message": "Service status app is running"} 13 14 15 @app.get("/status") 16 def get_status(): 17 try: 18 response = requests.get(STATUS_URL, timeout=5) 19 data = response.json() 20 return { 21 "source": STATUS_URL, 22 "indicator": data["status"]["indicator"], 23 "description": data["status"]["description"], 24 } 25 except Exception as exc: 26 raise HTTPException(status_code=500, detail=f"Failed to fetch status: {exc}") 27 28 29 @app.get("/status/raw") 30 def get_raw_status(): 31 response = requests.get(STATUS_URL, timeout=5) 32 return response.json()