Update main.py
هذا الالتزام موجود في:
68
main.py
68
main.py
@@ -1,53 +1,35 @@
|
|||||||
"""Wudhu API - Prayer Times & Qibla"""
|
|
||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
import math
|
import math
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
app = FastAPI(title="Wudhu API", description="مواقيت الصلاة واتجاه القبلة", version="1.0.0")
|
app=FastAPI(title='Wudhu API')
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
app.add_middleware(CORSMiddleware,allow_origins=['*'],allow_methods=['*'],allow_headers=['*'])
|
||||||
|
|
||||||
# Prayer times (sample data - simplified)
|
T={'makkah':{'fajr':'04:15','dhuhr':'12:20','asr':'15:45','maghrib':'18:55','isha':'20:25'},
|
||||||
PRAYER_TIMES = {
|
'madinah':{'fajr':'04:20','dhuhr':'12:25','asr':'15:50','maghrib':'19:00','isha':'20:30'},
|
||||||
"makkah": {"fajr": "04:15", "sunrise": "05:45", "dhuhr": "12:20", "asr": "15:45", "maghrib": "18:55", "isha": "20:25"},
|
'riyadh':{'fajr':'03:55','dhuhr':'12:00','asr':'15:25','maghrib':'18:35','isha':'20:05'},
|
||||||
"madinah": {"fajr": "04:20", "sunrise": "05:50", "dhuhr": "12:25", "asr": "15:50", "maghrib": "19:00", "isha": "20:30"},
|
'dubai':{'fajr':'04:10','dhuhr':'12:25','asr':'15:50','maghrib':'19:10','isha':'20:40'},
|
||||||
"riyadh": {"fajr": "03:55", "sunrise": "05:25", "dhuhr": "12:00", "asr": "15:25", "maghrib": "18:35", "isha": "20:05"},
|
'cairo':{'fajr':'03:40','dhuhr':'11:55','asr':'15:20','maghrib':'18:40','isha':'20:10'}}
|
||||||
"jeddah": {"fajr": "04:25", "sunrise": "05:55", "dhuhr": "12:30", "asr": "15:55", "maghrib": "19:05", "isha": "20:35"},
|
|
||||||
"dubai": {"fajr": "04:10", "sunrise": "05:40", "dhuhr": "12:25", "asr": "15:50", "maghrib": "19:10", "isha": "20:40"},
|
|
||||||
"cairo": {"fajr": "03:40", "sunrise": "05:10", "dhuhr": "11:55", "asr": "15:20", "maghrib": "18:40", "isha": "20:10"},
|
|
||||||
}
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get('/')
|
||||||
def root():
|
def root(): return {'name':'Wudhu API','cities':list(T.keys())}
|
||||||
return {"name": "Wudhu API", "endpoints": ["/times", "/qibla", "/cities"]}
|
|
||||||
|
|
||||||
@app.get("/times")
|
@app.get('/times')
|
||||||
def prayer_times(city: str = Query("makkah", description="اسم المدينة بالإنجليزية")):
|
def times(city:str=Query('makkah')):
|
||||||
city = city.lower()
|
c=city.lower()
|
||||||
if city not in PRAYER_TIMES:
|
if c not in T: return {'error':f'Unknown: {list(T.keys())}'}
|
||||||
return {"error": f"المدينة غير موجودة. المدن: {list(PRAYER_TIMES.keys())}"}
|
return {'city':c,'date':str(date.today()),'times':T[c]}
|
||||||
return {"city": city, "date": str(date.today()), "times": PRAYER_TIMES[city]}
|
|
||||||
|
|
||||||
@app.get("/cities")
|
@app.get('/qibla')
|
||||||
def cities():
|
def qibla(lat:float,lng:float):
|
||||||
return {"cities": list(PRAYER_TIMES.keys())}
|
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)}
|
||||||
|
|
||||||
@app.get("/qibla")
|
if __name__=='__main__':
|
||||||
def qibla_direction(lat: float, lng: float):
|
import uvicorn;uvicorn.run(app,host='0.0.0.0',port=8000)
|
||||||
"""Calculate Qibla direction from given coordinates"""
|
|
||||||
# Kaaba coordinates
|
|
||||||
kaaba_lat, kaaba_lng = 21.4225, 39.8262
|
|
||||||
lat_rad, lng_rad = math.radians(lat), math.radians(lng)
|
|
||||||
kaaba_lat_rad, kaaba_lng_rad = math.radians(kaaba_lat), math.radians(kaaba_lng)
|
|
||||||
|
|
||||||
delta_lng = kaaba_lng_rad - lng_rad
|
|
||||||
y = math.sin(delta_lng) * math.cos(kaaba_lat_rad)
|
|
||||||
x = math.cos(lat_rad) * math.sin(kaaba_lat_rad) - math.sin(lat_rad) * math.cos(kaaba_lat_rad) * math.cos(delta_lng)
|
|
||||||
bearing = math.degrees(math.atan2(y, x))
|
|
||||||
bearing = (bearing + 360) % 360
|
|
||||||
|
|
||||||
return {"latitude": lat, "longitude": lng, "qibla_bearing": round(bearing, 2), "unit": "degrees_from_north"}
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import uvicorn
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم