from fastapi import FastAPI, Query from fastapi.middleware.cors import CORSMiddleware import math from datetime import date app=FastAPI(title='Wudhu API') app.add_middleware(CORSMiddleware,allow_origins=['*'],allow_methods=['*'],allow_headers=['*']) T={'makkah':{'fajr':'04:15','dhuhr':'12:20','asr':'15:45','maghrib':'18:55','isha':'20:25'}, 'madinah':{'fajr':'04:20','dhuhr':'12:25','asr':'15:50','maghrib':'19:00','isha':'20:30'}, 'riyadh':{'fajr':'03:55','dhuhr':'12:00','asr':'15:25','maghrib':'18:35','isha':'20:05'}, 'dubai':{'fajr':'04:10','dhuhr':'12:25','asr':'15:50','maghrib':'19:10','isha':'20:40'}, 'cairo':{'fajr':'03:40','dhuhr':'11:55','asr':'15:20','maghrib':'18:40','isha':'20:10'}} @app.get('/') def root(): return {'name':'Wudhu API','cities':list(T.keys())} @app.get('/times') def times(city:str=Query('makkah')): c=city.lower() if c not in T: return {'error':f'Unknown: {list(T.keys())}'} return {'city':c,'date':str(date.today()),'times':T[c]} @app.get('/qibla') def qibla(lat:float,lng:float): KA=(21.4225,39.8262) d=math.radians(KA[1]-lng) lr,kr=math.radians(lat),math.radians(KA[0]) y=math.sin(d)*math.cos(kr) x=math.cos(lr)*math.sin(kr)-math.sin(lr)*math.cos(kr)*math.cos(d) b=(math.degrees(math.atan2(y,x))+360)%360 return {'bearing':round(b,2)} if __name__=='__main__': import uvicorn;uvicorn.run(app,host='0.0.0.0',port=8000)