Spaces:
Sleeping
Sleeping
File size: 1,549 Bytes
d2226ad |
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 |
from pydantic import BaseModel
from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="project_orb_v1_user_001")
from fastapi import APIRouter, HTTPException
router = APIRouter()
from schemas import SkyRequest, SkyResponse
from astronomy import calculate_sky_at_location
@router.get("/health") # Simple heartbeat check to verify server is running.
async def health_check():
return {"status": "alive", "project": "Orb"}
@router.post("/sky", response_model = SkyResponse)
async def get_sky_data(payload: SkyRequest):
try:
result = calculate_sky_at_location(
lat = payload.latitude,
lon = payload.longitude,
time_obj = payload.time
)
return result
except FileNotFoundError as e:
raise HTTPException(status_code = 500, detail = f"Data missing: {str(e)}")
except Exception as e:
raise HTTPException(status_code = 500, detail = str(e))
class LocationQuery(BaseModel):
query: str
@router.post("/geocode")
async def geocode_location(payload: LocationQuery):
try:
location = geolocator.geocode(payload.query)
if location:
return {
"status": "success",
"name": location.address,
"latitude": location.latitude,
"longitude": location.longitude
}
else:
raise HTTPException(status_code = 404, detail = "Location not found")
except Exception as e:
raise HTTPException(status_code = 500, detail = str(e))
|