python-esolat 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esolat/__init__.py +48 -0
- esolat/client.py +412 -0
- esolat/constants.py +122 -0
- esolat/exceptions.py +13 -0
- esolat/models.py +64 -0
- python_esolat-0.1.0.dist-info/METADATA +92 -0
- python_esolat-0.1.0.dist-info/RECORD +10 -0
- python_esolat-0.1.0.dist-info/WHEEL +5 -0
- python_esolat-0.1.0.dist-info/licenses/LICENSE +5 -0
- python_esolat-0.1.0.dist-info/top_level.txt +1 -0
esolat/__init__.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
python-esolat — Asynchronous Python client for Malaysian & Global Prayer Times.
|
|
3
|
+
|
|
4
|
+
Official JAKIM e-Solat & WaktuSolat in Malaysia, and Aladhan API worldwide.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .client import (
|
|
8
|
+
EsolatClient,
|
|
9
|
+
get_current_time_utc,
|
|
10
|
+
get_islamic_events,
|
|
11
|
+
get_prayer_times,
|
|
12
|
+
is_malaysia,
|
|
13
|
+
)
|
|
14
|
+
from .constants import (
|
|
15
|
+
ALADHAN_METHODS,
|
|
16
|
+
API_ENDPOINTS,
|
|
17
|
+
DHUHA_OFFSET_MINUTES,
|
|
18
|
+
HIJRI_MONTHS,
|
|
19
|
+
ISYRAQ_OFFSET_MINUTES,
|
|
20
|
+
MALAYSIA_BOUNDS,
|
|
21
|
+
ZONES,
|
|
22
|
+
)
|
|
23
|
+
from .exceptions import EsolatError, EsolatNetworkError, EsolatParseError
|
|
24
|
+
from .models import IslamicEvent, PrayerTimesDay, PrayerTimesResult
|
|
25
|
+
|
|
26
|
+
__version__ = "0.1.0"
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"ALADHAN_METHODS",
|
|
30
|
+
"API_ENDPOINTS",
|
|
31
|
+
"DHUHA_OFFSET_MINUTES",
|
|
32
|
+
"EsolatClient",
|
|
33
|
+
"EsolatError",
|
|
34
|
+
"EsolatNetworkError",
|
|
35
|
+
"EsolatParseError",
|
|
36
|
+
"HIJRI_MONTHS",
|
|
37
|
+
"ISYRAQ_OFFSET_MINUTES",
|
|
38
|
+
"IslamicEvent",
|
|
39
|
+
"MALAYSIA_BOUNDS",
|
|
40
|
+
"PrayerTimesDay",
|
|
41
|
+
"PrayerTimesResult",
|
|
42
|
+
"ZONES",
|
|
43
|
+
"__version__",
|
|
44
|
+
"get_current_time_utc",
|
|
45
|
+
"get_islamic_events",
|
|
46
|
+
"get_prayer_times",
|
|
47
|
+
"is_malaysia",
|
|
48
|
+
]
|
esolat/client.py
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
"""Core asynchronous client for esolat."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from datetime import datetime, timezone, timedelta
|
|
5
|
+
from typing import Optional, Any
|
|
6
|
+
import aiohttp
|
|
7
|
+
|
|
8
|
+
from .constants import (
|
|
9
|
+
API_ENDPOINTS,
|
|
10
|
+
DHUHA_OFFSET_MINUTES,
|
|
11
|
+
ISYRAQ_OFFSET_MINUTES,
|
|
12
|
+
HIJRI_MONTHS,
|
|
13
|
+
MALAYSIA_BOUNDS,
|
|
14
|
+
ZONES,
|
|
15
|
+
)
|
|
16
|
+
from .exceptions import EsolatError, EsolatNetworkError, EsolatParseError
|
|
17
|
+
from .models import IslamicEvent, PrayerTimesDay, PrayerTimesResult
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def is_malaysia(lat: Optional[float], lon: Optional[float]) -> bool:
|
|
21
|
+
"""Return True if coordinates fall within Malaysia's geographic bounds."""
|
|
22
|
+
if lat is None or lon is None:
|
|
23
|
+
return False
|
|
24
|
+
return (
|
|
25
|
+
MALAYSIA_BOUNDS["lat_min"] <= lat <= MALAYSIA_BOUNDS["lat_max"]
|
|
26
|
+
and MALAYSIA_BOUNDS["lon_min"] <= lon <= MALAYSIA_BOUNDS["lon_max"]
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def get_current_time_utc() -> str:
|
|
31
|
+
"""Return current UTC time in ISO 8601 format."""
|
|
32
|
+
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _epoch_to_iso(ts: int) -> str:
|
|
36
|
+
"""Convert Unix epoch timestamp to ISO 8601 UTC string."""
|
|
37
|
+
dt = datetime.fromtimestamp(ts, tz=timezone.utc)
|
|
38
|
+
return dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _day_name(year: int, month: int, day: int) -> str:
|
|
42
|
+
"""Return English day name for a given date."""
|
|
43
|
+
return datetime(year, month, day).strftime("%A")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _parse_hijri_full(hijri_raw: str) -> str:
|
|
47
|
+
"""Convert YYYY-MM-DD Hijri string to friendly label (e.g. 21 Jamadil Awwal 1448)."""
|
|
48
|
+
parts = hijri_raw.split("-")
|
|
49
|
+
if len(parts) == 3:
|
|
50
|
+
year, month_num, day = parts[0], parts[1], int(parts[2])
|
|
51
|
+
month_name = HIJRI_MONTHS.get(month_num, month_num)
|
|
52
|
+
return f"{day} {month_name} {year}"
|
|
53
|
+
return hijri_raw
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _aladhan_time_to_iso(year: int, month: int, day: int, time_str: str) -> str:
|
|
57
|
+
"""
|
|
58
|
+
Parse Aladhan timing string (e.g. '05:32 (EST)' or '05:32 (+08)') into UTC ISO 8601.
|
|
59
|
+
"""
|
|
60
|
+
clean_time = time_str.split()[0]
|
|
61
|
+
hh, mm = map(int, clean_time.split(":")[:2])
|
|
62
|
+
|
|
63
|
+
offset_minutes = 0
|
|
64
|
+
if "(" in time_str:
|
|
65
|
+
tz_part = time_str.split("(")[1].rstrip(")")
|
|
66
|
+
if tz_part.startswith("+") or tz_part.startswith("-"):
|
|
67
|
+
sign = 1 if tz_part[0] == "+" else -1
|
|
68
|
+
raw_offset = tz_part[1:]
|
|
69
|
+
if len(raw_offset) == 4:
|
|
70
|
+
oh = int(raw_offset[:2])
|
|
71
|
+
om = int(raw_offset[2:])
|
|
72
|
+
offset_minutes = sign * (oh * 60 + om)
|
|
73
|
+
elif len(raw_offset) <= 2:
|
|
74
|
+
offset_minutes = sign * int(raw_offset) * 60
|
|
75
|
+
|
|
76
|
+
local_dt = datetime(year, month, day, hh, mm)
|
|
77
|
+
utc_dt = local_dt - timedelta(minutes=offset_minutes)
|
|
78
|
+
return utc_dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class EsolatClient:
|
|
82
|
+
"""Asynchronous client for Malaysian & Global prayer times."""
|
|
83
|
+
|
|
84
|
+
def __init__(
|
|
85
|
+
self,
|
|
86
|
+
session: Optional[aiohttp.ClientSession] = None,
|
|
87
|
+
timeout: float = 15.0,
|
|
88
|
+
user_agent: str = "python-esolat/0.1.0",
|
|
89
|
+
) -> None:
|
|
90
|
+
self._session = session
|
|
91
|
+
self._owns_session = False
|
|
92
|
+
self._timeout = aiohttp.ClientTimeout(total=timeout)
|
|
93
|
+
self._user_agent = user_agent
|
|
94
|
+
|
|
95
|
+
async def __aenter__(self) -> "EsolatClient":
|
|
96
|
+
return self
|
|
97
|
+
|
|
98
|
+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
|
|
99
|
+
await self.close()
|
|
100
|
+
|
|
101
|
+
async def _get_session(self) -> aiohttp.ClientSession:
|
|
102
|
+
if self._session is None or self._session.closed:
|
|
103
|
+
self._session = aiohttp.ClientSession(
|
|
104
|
+
timeout=self._timeout,
|
|
105
|
+
headers={"User-Agent": self._user_agent, "Accept": "application/json"},
|
|
106
|
+
)
|
|
107
|
+
self._owns_session = True
|
|
108
|
+
return self._session
|
|
109
|
+
|
|
110
|
+
async def close(self) -> None:
|
|
111
|
+
"""Close the underlying HTTP session if owned."""
|
|
112
|
+
if self._owns_session and self._session and not self._session.closed:
|
|
113
|
+
await self._session.close()
|
|
114
|
+
|
|
115
|
+
async def get_prayer_times(
|
|
116
|
+
self,
|
|
117
|
+
latitude: Optional[float] = None,
|
|
118
|
+
longitude: Optional[float] = None,
|
|
119
|
+
zone: Optional[str] = None,
|
|
120
|
+
month: Optional[int] = None,
|
|
121
|
+
year: Optional[int] = None,
|
|
122
|
+
aladhan_method: str = "2",
|
|
123
|
+
) -> PrayerTimesResult:
|
|
124
|
+
"""
|
|
125
|
+
Fetch monthly prayer times by GPS or Zone code.
|
|
126
|
+
Auto-routes to JAKIM/WaktuSolat for Malaysia and Aladhan API for international locations.
|
|
127
|
+
"""
|
|
128
|
+
now = datetime.now(timezone.utc)
|
|
129
|
+
target_year = year or now.year
|
|
130
|
+
target_month = month or now.month
|
|
131
|
+
target_zone = zone.lower() if zone else None
|
|
132
|
+
|
|
133
|
+
is_local = bool(target_zone or (latitude is not None and longitude is not None and is_malaysia(latitude, longitude)))
|
|
134
|
+
session = await self._get_session()
|
|
135
|
+
prayers: list[PrayerTimesDay] = []
|
|
136
|
+
detected_zone = target_zone.upper() if target_zone else None
|
|
137
|
+
provider = "JAKIM" if is_local else "Aladhan"
|
|
138
|
+
|
|
139
|
+
if is_local:
|
|
140
|
+
# 1. Primary: WaktuSolat API (GPS or Zone)
|
|
141
|
+
if target_zone:
|
|
142
|
+
url = f"{API_ENDPOINTS['waktu_solat_zone']}/{target_zone.upper()}?year={target_year}&month={target_month}"
|
|
143
|
+
else:
|
|
144
|
+
url = f"{API_ENDPOINTS['waktu_solat_gps']}/{latitude}/{longitude}?year={target_year}&month={target_month}"
|
|
145
|
+
|
|
146
|
+
success = False
|
|
147
|
+
try:
|
|
148
|
+
async with session.get(url) as resp:
|
|
149
|
+
if resp.status == 200:
|
|
150
|
+
raw = await resp.json()
|
|
151
|
+
detected_zone = raw.get("zone", detected_zone)
|
|
152
|
+
for d in raw.get("prayers", []):
|
|
153
|
+
day_num = d.get("day", 1)
|
|
154
|
+
syuruk_ts = int(d.get("syuruk", 0))
|
|
155
|
+
isyraq_ts = syuruk_ts + ISYRAQ_OFFSET_MINUTES * 60
|
|
156
|
+
dhuha_ts = syuruk_ts + DHUHA_OFFSET_MINUTES * 60
|
|
157
|
+
hijri_raw = str(d.get("hijri", ""))
|
|
158
|
+
|
|
159
|
+
prayers.append(
|
|
160
|
+
PrayerTimesDay(
|
|
161
|
+
date=f"{target_year:04d}-{target_month:02d}-{day_num:02d}",
|
|
162
|
+
day_name=_day_name(target_year, target_month, day_num),
|
|
163
|
+
hijri_raw=hijri_raw,
|
|
164
|
+
hijri_full=_parse_hijri_full(hijri_raw),
|
|
165
|
+
fajr=_epoch_to_iso(int(d.get("fajr", 0))),
|
|
166
|
+
syuruk=_epoch_to_iso(syuruk_ts),
|
|
167
|
+
isyraq=_epoch_to_iso(isyraq_ts),
|
|
168
|
+
dhuha=_epoch_to_iso(dhuha_ts),
|
|
169
|
+
dhuhr=_epoch_to_iso(int(d.get("dhuhr", 0))),
|
|
170
|
+
asr=_epoch_to_iso(int(d.get("asr", 0))),
|
|
171
|
+
maghrib=_epoch_to_iso(int(d.get("maghrib", 0))),
|
|
172
|
+
isha=_epoch_to_iso(int(d.get("isha", 0))),
|
|
173
|
+
imsak=_epoch_to_iso(int(d.get("imsak", 0))) if d.get("imsak") else None,
|
|
174
|
+
provider="JAKIM",
|
|
175
|
+
)
|
|
176
|
+
)
|
|
177
|
+
success = True
|
|
178
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
|
179
|
+
# Fallback to JAKIM Takwim if zone available
|
|
180
|
+
if not target_zone:
|
|
181
|
+
raise EsolatNetworkError(f"Failed to query WaktuSolat GPS: {err}") from err
|
|
182
|
+
|
|
183
|
+
if not success and target_zone:
|
|
184
|
+
# 2. Fallback: JAKIM Takwim Solat API
|
|
185
|
+
start_date = f"{target_year:04d}-{target_month:02d}-01"
|
|
186
|
+
# Last day of month
|
|
187
|
+
if target_month == 12:
|
|
188
|
+
end_date = f"{target_year:04d}-12-31"
|
|
189
|
+
else:
|
|
190
|
+
next_month = datetime(target_year, target_month + 1, 1)
|
|
191
|
+
last_day = (next_month - timedelta(days=1)).day
|
|
192
|
+
end_date = f"{target_year:04d}-{target_month:02d}-{last_day:02d}"
|
|
193
|
+
|
|
194
|
+
takwim_url = f"{API_ENDPOINTS['jakim_takwim']}{target_zone.upper()}"
|
|
195
|
+
try:
|
|
196
|
+
form_data = aiohttp.FormData()
|
|
197
|
+
form_data.add_field("datestart", start_date)
|
|
198
|
+
form_data.add_field("dateend", end_date)
|
|
199
|
+
async with session.post(takwim_url, data=form_data) as resp:
|
|
200
|
+
if resp.status == 200:
|
|
201
|
+
raw = await resp.json()
|
|
202
|
+
for item in raw.get("prayerTime", []):
|
|
203
|
+
greg_date = item.get("date", "")
|
|
204
|
+
parts = greg_date.split("-")
|
|
205
|
+
if len(parts) == 3:
|
|
206
|
+
y, m, d = int(parts[0]), int(parts[1]), int(parts[2])
|
|
207
|
+
else:
|
|
208
|
+
continue
|
|
209
|
+
|
|
210
|
+
hijri_raw = item.get("hijri", "")
|
|
211
|
+
# JAKIM Takwim times are in local MYT (+08:00) HH:MM:SS
|
|
212
|
+
def to_utc(val: str) -> str:
|
|
213
|
+
t = val.strip().split(" ")[0]
|
|
214
|
+
hh, mm = map(int, t.split(":")[:2])
|
|
215
|
+
dt = datetime(y, m, d, hh, mm) - timedelta(hours=8)
|
|
216
|
+
return dt.strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
217
|
+
|
|
218
|
+
syuruk_iso = to_utc(item.get("syuruk", "00:00:00"))
|
|
219
|
+
s_dt = datetime.strptime(syuruk_iso, "%Y-%m-%dT%H:%M:%SZ")
|
|
220
|
+
isyraq_iso = (s_dt + timedelta(minutes=ISYRAQ_OFFSET_MINUTES)).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
221
|
+
dhuha_iso = (s_dt + timedelta(minutes=DHUHA_OFFSET_MINUTES)).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
222
|
+
|
|
223
|
+
prayers.append(
|
|
224
|
+
PrayerTimesDay(
|
|
225
|
+
date=greg_date,
|
|
226
|
+
day_name=_day_name(y, m, d),
|
|
227
|
+
hijri_raw=hijri_raw,
|
|
228
|
+
hijri_full=_parse_hijri_full(hijri_raw),
|
|
229
|
+
fajr=to_utc(item.get("fajr", "00:00:00")),
|
|
230
|
+
syuruk=syuruk_iso,
|
|
231
|
+
isyraq=isyraq_iso,
|
|
232
|
+
dhuha=dhuha_iso,
|
|
233
|
+
dhuhr=to_utc(item.get("dhuhr", "00:00:00")),
|
|
234
|
+
asr=to_utc(item.get("asr", "00:00:00")),
|
|
235
|
+
maghrib=to_utc(item.get("maghrib", "00:00:00")),
|
|
236
|
+
isha=to_utc(item.get("isha", "00:00:00")),
|
|
237
|
+
imsak=to_utc(item.get("imsak", "00:00:00")) if item.get("imsak") else None,
|
|
238
|
+
provider="JAKIM",
|
|
239
|
+
)
|
|
240
|
+
)
|
|
241
|
+
except Exception as err:
|
|
242
|
+
raise EsolatNetworkError(f"Failed to query JAKIM takwim API: {err}") from err
|
|
243
|
+
|
|
244
|
+
else:
|
|
245
|
+
# 3. Global: Aladhan Calendar API
|
|
246
|
+
if latitude is None or longitude is None:
|
|
247
|
+
raise EsolatError("Coordinates (latitude, longitude) required for locations outside Malaysia.")
|
|
248
|
+
|
|
249
|
+
url = f"{API_ENDPOINTS['aladhan_calendar']}?latitude={latitude}&longitude={longitude}&method={aladhan_method}&month={target_month}&year={target_year}"
|
|
250
|
+
try:
|
|
251
|
+
async with session.get(url) as resp:
|
|
252
|
+
if resp.status != 200:
|
|
253
|
+
raise EsolatNetworkError(f"Aladhan API answered HTTP {resp.status}")
|
|
254
|
+
raw = await resp.json()
|
|
255
|
+
for item in raw.get("data", []):
|
|
256
|
+
timings = item.get("timings", {})
|
|
257
|
+
greg_info = item.get("date", {}).get("gregorian", {})
|
|
258
|
+
raw_date = greg_info.get("date", "") # "DD-MM-YYYY"
|
|
259
|
+
d_parts = raw_date.split("-")
|
|
260
|
+
if len(d_parts) == 3:
|
|
261
|
+
dd, mm, yyyy = int(d_parts[0]), int(d_parts[1]), int(d_parts[2])
|
|
262
|
+
else:
|
|
263
|
+
continue
|
|
264
|
+
|
|
265
|
+
parsed_date = f"{yyyy:04d}-{mm:02d}-{dd:02d}"
|
|
266
|
+
day_title = greg_info.get("weekday", {}).get("en") or _day_name(yyyy, mm, dd)
|
|
267
|
+
|
|
268
|
+
hijri_info = item.get("date", {}).get("hijri", {})
|
|
269
|
+
h_month = f"{int(hijri_info.get('month', {}).get('number', 1)):02d}"
|
|
270
|
+
h_day = str(hijri_info.get("day", "01")).zfill(2)
|
|
271
|
+
h_year = str(hijri_info.get("year", ""))
|
|
272
|
+
hijri_raw = f"{h_year}-{h_month}-{h_day}"
|
|
273
|
+
hijri_full = f"{int(h_day)} {HIJRI_MONTHS.get(h_month, h_month)} {h_year}"
|
|
274
|
+
|
|
275
|
+
syuruk_iso = _aladhan_time_to_iso(yyyy, mm, dd, timings.get("Sunrise", "00:00"))
|
|
276
|
+
s_dt = datetime.strptime(syuruk_iso, "%Y-%m-%dT%H:%M:%SZ")
|
|
277
|
+
isyraq_iso = (s_dt + timedelta(minutes=ISYRAQ_OFFSET_MINUTES)).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
278
|
+
dhuha_iso = (s_dt + timedelta(minutes=DHUHA_OFFSET_MINUTES)).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
279
|
+
|
|
280
|
+
prayers.append(
|
|
281
|
+
PrayerTimesDay(
|
|
282
|
+
date=parsed_date,
|
|
283
|
+
day_name=day_title,
|
|
284
|
+
hijri_raw=hijri_raw,
|
|
285
|
+
hijri_full=hijri_full,
|
|
286
|
+
fajr=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Fajr", "00:00")),
|
|
287
|
+
syuruk=syuruk_iso,
|
|
288
|
+
isyraq=isyraq_iso,
|
|
289
|
+
dhuha=dhuha_iso,
|
|
290
|
+
dhuhr=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Dhuhr", "00:00")),
|
|
291
|
+
asr=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Asr", "00:00")),
|
|
292
|
+
maghrib=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Maghrib", "00:00")),
|
|
293
|
+
isha=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Isha", "00:00")),
|
|
294
|
+
imsak=_aladhan_time_to_iso(yyyy, mm, dd, timings.get("Imsak", "00:00")) if timings.get("Imsak") else None,
|
|
295
|
+
provider="Aladhan",
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
|
299
|
+
raise EsolatNetworkError(f"Failed to query Aladhan API: {err}") from err
|
|
300
|
+
|
|
301
|
+
prayers.sort(key=lambda x: x.date)
|
|
302
|
+
return PrayerTimesResult(
|
|
303
|
+
current_time_utc=get_current_time_utc(),
|
|
304
|
+
prayers=prayers,
|
|
305
|
+
zone=detected_zone,
|
|
306
|
+
provider=provider,
|
|
307
|
+
latitude=latitude,
|
|
308
|
+
longitude=longitude,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
async def get_islamic_events(
|
|
312
|
+
self,
|
|
313
|
+
year: Optional[int] = None,
|
|
314
|
+
is_malaysia: bool = True,
|
|
315
|
+
) -> list[IslamicEvent]:
|
|
316
|
+
"""
|
|
317
|
+
Fetch major Islamic calendar events and milestones.
|
|
318
|
+
Uses official JAKIM e-Solat for Malaysia and Aladhan API globally.
|
|
319
|
+
"""
|
|
320
|
+
target_year = year or datetime.now(timezone.utc).year
|
|
321
|
+
session = await self._get_session()
|
|
322
|
+
events: list[IslamicEvent] = []
|
|
323
|
+
|
|
324
|
+
if is_malaysia:
|
|
325
|
+
try:
|
|
326
|
+
async with session.get(API_ENDPOINTS["jakim_events"]) as resp:
|
|
327
|
+
if resp.status != 200:
|
|
328
|
+
raise EsolatNetworkError(f"JAKIM Islamic events answered HTTP {resp.status}")
|
|
329
|
+
raw = await resp.json()
|
|
330
|
+
for item in raw.get("event", []):
|
|
331
|
+
greg_date = item.get("tarikh_miladi", "")
|
|
332
|
+
if greg_date.startswith(str(target_year)):
|
|
333
|
+
events.append(
|
|
334
|
+
IslamicEvent(
|
|
335
|
+
event_name=item.get("hari_peristiwa", "").replace("*", "").strip(),
|
|
336
|
+
gregorian_date=greg_date,
|
|
337
|
+
hijri_date=item.get("tarikh_hijri", ""),
|
|
338
|
+
)
|
|
339
|
+
)
|
|
340
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
|
341
|
+
raise EsolatNetworkError(f"Failed to fetch JAKIM events: {err}") from err
|
|
342
|
+
else:
|
|
343
|
+
url = f"{API_ENDPOINTS['aladhan_events']}?year={target_year}"
|
|
344
|
+
try:
|
|
345
|
+
async with session.get(url) as resp:
|
|
346
|
+
if resp.status != 200:
|
|
347
|
+
raise EsolatNetworkError(f"Aladhan events answered HTTP {resp.status}")
|
|
348
|
+
raw = await resp.json()
|
|
349
|
+
for item in raw.get("data", []):
|
|
350
|
+
raw_date = item.get("gregorianDate", "") # "DD-MM-YYYY"
|
|
351
|
+
d_parts = raw_date.split("-")
|
|
352
|
+
if len(d_parts) == 3:
|
|
353
|
+
parsed_greg = f"{d_parts[2]}-{d_parts[1]}-{d_parts[0]}"
|
|
354
|
+
else:
|
|
355
|
+
parsed_greg = raw_date
|
|
356
|
+
|
|
357
|
+
h_month = str(item.get("hijriMonth", 1)).zfill(2)
|
|
358
|
+
h_day = str(item.get("hijriDay", 1)).zfill(2)
|
|
359
|
+
h_year = str(item.get("hijriYear", ""))
|
|
360
|
+
name = (item.get("arahName") or item.get("label") or "").strip()
|
|
361
|
+
|
|
362
|
+
events.append(
|
|
363
|
+
IslamicEvent(
|
|
364
|
+
event_name=name,
|
|
365
|
+
gregorian_date=parsed_greg,
|
|
366
|
+
hijri_date=f"{h_year}-{h_month}-{h_day}",
|
|
367
|
+
)
|
|
368
|
+
)
|
|
369
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as err:
|
|
370
|
+
raise EsolatNetworkError(f"Failed to fetch Aladhan events: {err}") from err
|
|
371
|
+
|
|
372
|
+
events.sort(key=lambda x: x.gregorian_date)
|
|
373
|
+
return events
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
# ─── Standalone Convenience Functions ──────────────────────────────────────────
|
|
377
|
+
|
|
378
|
+
async def get_prayer_times(
|
|
379
|
+
latitude: Optional[float] = None,
|
|
380
|
+
longitude: Optional[float] = None,
|
|
381
|
+
zone: Optional[str] = None,
|
|
382
|
+
month: Optional[int] = None,
|
|
383
|
+
year: Optional[int] = None,
|
|
384
|
+
aladhan_method: str = "2",
|
|
385
|
+
session: Optional[aiohttp.ClientSession] = None,
|
|
386
|
+
) -> PrayerTimesResult:
|
|
387
|
+
"""Fetch monthly prayer times using a temporary or shared aiohttp session."""
|
|
388
|
+
client = EsolatClient(session=session)
|
|
389
|
+
try:
|
|
390
|
+
return await client.get_prayer_times(
|
|
391
|
+
latitude=latitude,
|
|
392
|
+
longitude=longitude,
|
|
393
|
+
zone=zone,
|
|
394
|
+
month=month,
|
|
395
|
+
year=year,
|
|
396
|
+
aladhan_method=aladhan_method,
|
|
397
|
+
)
|
|
398
|
+
finally:
|
|
399
|
+
await client.close()
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
async def get_islamic_events(
|
|
403
|
+
year: Optional[int] = None,
|
|
404
|
+
is_malaysia: bool = True,
|
|
405
|
+
session: Optional[aiohttp.ClientSession] = None,
|
|
406
|
+
) -> list[IslamicEvent]:
|
|
407
|
+
"""Fetch major Islamic calendar events using a temporary or shared aiohttp session."""
|
|
408
|
+
client = EsolatClient(session=session)
|
|
409
|
+
try:
|
|
410
|
+
return await client.get_islamic_events(year=year, is_malaysia=is_malaysia)
|
|
411
|
+
finally:
|
|
412
|
+
await client.close()
|
esolat/constants.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
DHUHA_OFFSET_MINUTES = 28
|
|
2
|
+
ISYRAQ_OFFSET_MINUTES = 12
|
|
3
|
+
|
|
4
|
+
MALAYSIA_BOUNDS = {
|
|
5
|
+
"lat_min": 1.0,
|
|
6
|
+
"lat_max": 7.5,
|
|
7
|
+
"lon_min": 99.5,
|
|
8
|
+
"lon_max": 119.5,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
HIJRI_MONTHS: dict[str, str] = {
|
|
12
|
+
"01": "Muharram",
|
|
13
|
+
"02": "Safar",
|
|
14
|
+
"03": "Rabi'ul Awwal",
|
|
15
|
+
"04": "Rabi'ul Akhir",
|
|
16
|
+
"05": "Jamadil Awwal",
|
|
17
|
+
"06": "Jamadil Akhir",
|
|
18
|
+
"07": "Rejab",
|
|
19
|
+
"08": "Sha'aban",
|
|
20
|
+
"09": "Ramadhan",
|
|
21
|
+
"10": "Syawal",
|
|
22
|
+
"11": "Zulkaedah",
|
|
23
|
+
"12": "Zulhijjah",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
API_ENDPOINTS = {
|
|
27
|
+
"waktu_solat_gps": "https://api.waktusolat.app/v2/solat/gps",
|
|
28
|
+
"waktu_solat_zone": "https://api.waktusolat.app/v2/solat",
|
|
29
|
+
"jakim_takwim": "https://www.e-solat.gov.my/index.php?r=esolatApi/takwimsolat&period=duration&zone=",
|
|
30
|
+
"jakim_events": "https://www.e-solat.gov.my/index.php?r=esolatApi/islamicevent&type=all",
|
|
31
|
+
"aladhan_calendar": "https://api.aladhan.com/v1/calendar",
|
|
32
|
+
"aladhan_timings": "https://api.aladhan.com/v1/timings",
|
|
33
|
+
"aladhan_events": "https://api.aladhan.com/v1/islamicEvents",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
ALADHAN_METHODS = [
|
|
37
|
+
"0", # Shia Ithna-Ashari, Leva Institute, Qum
|
|
38
|
+
"1", # University of Islamic Sciences, Karachi
|
|
39
|
+
"2", # Islamic Society of North America (ISNA) - Default
|
|
40
|
+
"3", # Muslim World League (MWL)
|
|
41
|
+
"4", # Umm Al-Qura University, Makkah
|
|
42
|
+
"5", # Egyptian General Authority of Survey
|
|
43
|
+
"7", # Institute of Geophysics, University of Tehran
|
|
44
|
+
"8", # Gulf Region
|
|
45
|
+
"9", # Kuwait
|
|
46
|
+
"10", # Qatar
|
|
47
|
+
"11", # Majlis Ugama Islam Singapura, Singapore
|
|
48
|
+
"12", # Union Organization islamique de France
|
|
49
|
+
"13", # Diyanet İşleri Başkanlığı, Turkey
|
|
50
|
+
"14", # Spiritual Administration of Muslims of Russia
|
|
51
|
+
"15", # Moonsighting Committee Worldwide
|
|
52
|
+
"16", # Dubai (unofficial)
|
|
53
|
+
"17", # Jabatan Kemajuan Islam Malaysia (JAKIM)
|
|
54
|
+
"18", # Tunisia
|
|
55
|
+
"19", # Algeria
|
|
56
|
+
"20", # KEMENAG - Kementerian Agama Republik Indonesia
|
|
57
|
+
"21", # Morocco
|
|
58
|
+
"22", # Comunidade Islamica de Lisboa
|
|
59
|
+
"23", # Ministry of Awqaf, Islamic Affairs and Holy Sanctuaries, Jordan
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
ZONES: dict[str, str] = {
|
|
63
|
+
"jhr01": "JHR01 - Pulau Aur dan Pulau Pemanggil",
|
|
64
|
+
"jhr02": "JHR02 - Johor Bahru, Kota Tinggi, Mersing, Kulai",
|
|
65
|
+
"jhr03": "JHR03 - Kluang, Pontian",
|
|
66
|
+
"jhr04": "JHR04 - Batu Pahat, Muar, Segamat, Gemas Johor, Tangkak",
|
|
67
|
+
"kdh01": "KDH01 - Kota Setar, Kubang Pasu, Pokok Sena",
|
|
68
|
+
"kdh02": "KDH02 - Kuala Muda, Yan, Pendang",
|
|
69
|
+
"kdh03": "KDH03 - Padang Terap, Sik",
|
|
70
|
+
"kdh04": "KDH04 - Baling",
|
|
71
|
+
"kdh05": "KDH05 - Bandar Baharu, Kulim",
|
|
72
|
+
"kdh06": "KDH06 - Langkawi",
|
|
73
|
+
"kdh07": "KDH07 - Puncak Gunung Jerai",
|
|
74
|
+
"ktn01": "KTN01 - Bachok, Kota Bharu, Machang, Pasir Mas, Pasir Puteh, Tanah Merah, Tumpat, Kuala Krai, Mukim Chiku",
|
|
75
|
+
"ktn02": "KTN02 - Gua Musang, Jeli, Jajahan Kecil Lojing",
|
|
76
|
+
"mlk01": "MLK01 - Seluruh Negeri Melaka",
|
|
77
|
+
"ngs01": "NGS01 - Tampin, Jempol",
|
|
78
|
+
"ngs02": "NGS02 - Jelebu, Kuala Pilah, Rembau",
|
|
79
|
+
"ngs03": "NGS03 - Port Dickson, Seremban",
|
|
80
|
+
"phg01": "PHG01 - Pulau Tioman",
|
|
81
|
+
"phg02": "PHG02 - Kuantan, Pekan, Muadzam Shah",
|
|
82
|
+
"phg03": "PHG03 - Jerantut, Temerloh, Maran, Bera, Chenor, Jengka",
|
|
83
|
+
"phg04": "PHG04 - Bentong, Lipis, Raub",
|
|
84
|
+
"phg05": "PHG05 - Genting Sempah, Janda Baik, Bukit Tinggi",
|
|
85
|
+
"phg06": "PHG06 - Cameron Highlands, Genting Highlands, Bukit Fraser",
|
|
86
|
+
"pls01": "PLS01 - Seluruh Negeri Perlis",
|
|
87
|
+
"png01": "PNG01 - Seluruh Negeri Pulau Pinang",
|
|
88
|
+
"prk01": "PRK01 - Tapah, Slim River, Tanjung Malim",
|
|
89
|
+
"prk02": "PRK02 - Kuala Kangsar, Sg. Siput, Ipoh, Batu Gajah, Kampar",
|
|
90
|
+
"prk03": "PRK03 - Lenggong, Pengkalan Hulu, Grik",
|
|
91
|
+
"prk04": "PRK04 - Temengor, Belum",
|
|
92
|
+
"prk05": "PRK05 - Teluk Intan, Bagan Datuk, Kg Gajah, Seri Iskandar, Beruas, Parit, Lumut, Sitiawan, Pulau Pangkor",
|
|
93
|
+
"prk06": "PRK06 - Selama, Taiping, Bagan Serai, Parit Buntar",
|
|
94
|
+
"prk07": "PRK07 - Bukit Larut",
|
|
95
|
+
"sbh01": "SBH01 - Bahagian Sandakan (Timur)",
|
|
96
|
+
"sbh02": "SBH02 - Beluran, Telupid, Pinangah, Terusan, Kuamut, Bahagian Sandakan (Barat)",
|
|
97
|
+
"sbh03": "SBH03 - Lahad Datu, Silabukan, Kunak, Sahabat, Semporna, Tungku, Bahagian Tawau (Timur)",
|
|
98
|
+
"sbh04": "SBH04 - Bandar Tawau, Balung, Merotai, Kalabakan, Bahagian Tawau (Barat)",
|
|
99
|
+
"sbh05": "SBH05 - Kudat, Kota Marudu, Pitas, Pulau Banggi, Bahagian Kudat",
|
|
100
|
+
"sbh06": "SBH06 - Gunung Kinabalu",
|
|
101
|
+
"sbh07": "SBH07 - Kota Kinabalu, Ranau, Kota Belud, Tuaran, Penampang, Papar, Putatan, Bahagian Pantai Barat",
|
|
102
|
+
"sbh08": "SBH08 - Pensiangan, Keningau, Tambunan, Nabawan, Bahagian Pendalaman (Atas)",
|
|
103
|
+
"sbh09": "SBH09 - Beaufort, Kuala Penyu, Sipitang, Tenom, Long Pa Sia, Membakut, Weston, Bahagian Pendalaman (Bawah)",
|
|
104
|
+
"sgr01": "SGR01 - Gombak, Petaling, Sepang, Hulu Langat, Hulu Selangor, Shah Alam",
|
|
105
|
+
"sgr02": "SGR02 - Kuala Selangor, Sabak Bernam",
|
|
106
|
+
"sgr03": "SGR03 - Klang, Kuala Langat",
|
|
107
|
+
"swk01": "SWK01 - Limbang, Lawas, Sundar, Trusan",
|
|
108
|
+
"swk02": "SWK02 - Miri, Niah, Bekenu, Sibuti, Marudi",
|
|
109
|
+
"swk03": "SWK03 - Pandan, Belaga, Suai, Tatau, Sebauh, Bintulu",
|
|
110
|
+
"swk04": "SWK04 - Sibu, Mukah, Dalat, Song, Igan, Oya, Balingian, Kanowit, Kapit",
|
|
111
|
+
"swk05": "SWK05 - Sarikei, Matu, Julau, Rajang, Daro, Bintangor, Belawai",
|
|
112
|
+
"swk06": "SWK06 - Lubok Antu, Sri Aman, Roban, Debak, Betong, Saratok, Barat",
|
|
113
|
+
"swk07": "SWK07 - Serian, Simunjan, Samarahan, Sebuyau, Meludam",
|
|
114
|
+
"swk08": "SWK08 - Kuching, Bau, Lundu, Sematan",
|
|
115
|
+
"swk09": "SWK09 - Zon Khas (Kampung Matang)",
|
|
116
|
+
"trg01": "TRG01 - Kuala Terengganu, Marang, Kuala Nerus",
|
|
117
|
+
"trg02": "TRG02 - Besut, Setiu",
|
|
118
|
+
"trg03": "TRG03 - Hulu Terengganu",
|
|
119
|
+
"trg04": "TRG04 - Dungun, Kemaman",
|
|
120
|
+
"wly01": "WLY01 - Kuala Lumpur, Putrajaya",
|
|
121
|
+
"wly02": "WLY02 - Labuan",
|
|
122
|
+
}
|
esolat/exceptions.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Exceptions for the esolat package."""
|
|
2
|
+
|
|
3
|
+
class EsolatError(Exception):
|
|
4
|
+
"""Base exception for all esolat errors."""
|
|
5
|
+
pass
|
|
6
|
+
|
|
7
|
+
class EsolatNetworkError(EsolatError):
|
|
8
|
+
"""Raised when an HTTP or network error occurs connecting to upstream APIs."""
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
class EsolatParseError(EsolatError):
|
|
12
|
+
"""Raised when parsing upstream response data fails."""
|
|
13
|
+
pass
|
esolat/models.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Data models for esolat."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, asdict
|
|
4
|
+
from typing import Optional, Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class PrayerTimesDay:
|
|
9
|
+
"""Prayer timetable for a single day."""
|
|
10
|
+
|
|
11
|
+
date: str # YYYY-MM-DD
|
|
12
|
+
day_name: str # e.g. Sunday
|
|
13
|
+
hijri_raw: str # e.g. 1448-05-21
|
|
14
|
+
hijri_full: str # e.g. 21 Jamadil Awwal 1448
|
|
15
|
+
fajr: str # ISO 8601 UTC string (YYYY-MM-DDTHH:MM:SSZ)
|
|
16
|
+
syuruk: str # ISO 8601 UTC string
|
|
17
|
+
isyraq: str # ISO 8601 UTC string (+12m after Syuruk)
|
|
18
|
+
dhuha: str # ISO 8601 UTC string (+28m after Syuruk)
|
|
19
|
+
dhuhr: str # ISO 8601 UTC string
|
|
20
|
+
asr: str # ISO 8601 UTC string
|
|
21
|
+
maghrib: str # ISO 8601 UTC string
|
|
22
|
+
isha: str # ISO 8601 UTC string
|
|
23
|
+
imsak: Optional[str] = None
|
|
24
|
+
provider: str = "JAKIM"
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict[str, Any]:
|
|
27
|
+
"""Convert to dictionary representation."""
|
|
28
|
+
return asdict(self)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class PrayerTimesResult:
|
|
33
|
+
"""Complete monthly prayer times schedule and metadata."""
|
|
34
|
+
|
|
35
|
+
current_time_utc: str
|
|
36
|
+
prayers: list[PrayerTimesDay]
|
|
37
|
+
zone: Optional[str] = None
|
|
38
|
+
provider: str = "JAKIM"
|
|
39
|
+
latitude: Optional[float] = None
|
|
40
|
+
longitude: Optional[float] = None
|
|
41
|
+
|
|
42
|
+
def to_dict(self) -> dict[str, Any]:
|
|
43
|
+
"""Convert to dictionary representation."""
|
|
44
|
+
return {
|
|
45
|
+
"current_time_utc": self.current_time_utc,
|
|
46
|
+
"zone": self.zone,
|
|
47
|
+
"provider": self.provider,
|
|
48
|
+
"latitude": self.latitude,
|
|
49
|
+
"longitude": self.longitude,
|
|
50
|
+
"prayers": [p.to_dict() for p in self.prayers],
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class IslamicEvent:
|
|
56
|
+
"""Significant Islamic milestone or public holiday."""
|
|
57
|
+
|
|
58
|
+
event_name: str
|
|
59
|
+
gregorian_date: str # YYYY-MM-DD
|
|
60
|
+
hijri_date: str # YYYY-MM-DD
|
|
61
|
+
|
|
62
|
+
def to_dict(self) -> dict[str, Any]:
|
|
63
|
+
"""Convert to dictionary representation."""
|
|
64
|
+
return asdict(self)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-esolat
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Asynchronous Python client for Malaysian prayer times (official JAKIM/e-Solat) and worldwide Aladhan calculation
|
|
5
|
+
Author: Zubir Jamal
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/zubirjamal/python-esolat
|
|
8
|
+
Project-URL: Repository, https://github.com/zubirjamal/python-esolat
|
|
9
|
+
Project-URL: Issues, https://github.com/zubirjamal/python-esolat/issues
|
|
10
|
+
Keywords: esolat,waktusolat,jakim,prayer-times,solat,malaysia,aladhan,home-assistant
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Home Automation
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: aiohttp>=3.9.0
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=8.0.0; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "test"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# python-esolat
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/python-esolat/)
|
|
32
|
+
[](https://pypi.org/project/python-esolat/)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
|
|
35
|
+
Asynchronous Python client for Malaysian prayer times (official JAKIM/e-Solat & WaktuSolat) and worldwide Aladhan calculation.
|
|
36
|
+
|
|
37
|
+
Designed as the core prayer times engine for [Home Assistant eSolat GPS](https://github.com/zubir2k/homeassistant-esolatgps), [eSolat Takwim](https://github.com/zubir2k/homeassistant-esolattakwim), and [esolat-mcp](https://github.com/zubir2k/esolat-mcp).
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Automated Routing**:
|
|
42
|
+
- **Malaysia (GPS or Zone)**: Fetches official JAKIM timetable via WaktuSolat API (with automatic fallback to JAKIM e-Solat Takwim API).
|
|
43
|
+
- **Worldwide (outside Malaysia)**: Automatically queries the Aladhan API with configurable calculation methods.
|
|
44
|
+
- **Derived Islamic Times**:
|
|
45
|
+
- Auto-calculates **Isyraq** (+12m) and **Dhuha** (+28m) after Syuruk/Sunrise.
|
|
46
|
+
- **Hijri Calendar Integration**:
|
|
47
|
+
- Full Hijri date parsing with friendly month names (e.g. `21 Jamadil Awwal 1448`).
|
|
48
|
+
- **Major Islamic Events**:
|
|
49
|
+
- Annual Islamic calendar events and public milestones (JAKIM for Malaysia, Aladhan globally).
|
|
50
|
+
- **Modern Python**:
|
|
51
|
+
- Async-first (`aiohttp`), strongly typed dataclasses (`PrayerTimesResult`, `PrayerTimesDay`, `IslamicEvent`).
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pip install python-esolat
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Quick Start
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import asyncio
|
|
63
|
+
from esolat import EsolatClient
|
|
64
|
+
|
|
65
|
+
async def main():
|
|
66
|
+
async with EsolatClient() as client:
|
|
67
|
+
# 1. Fetch by GPS coordinates (Malaysia -> JAKIM / WaktuSolat)
|
|
68
|
+
res = await client.get_prayer_times(latitude=3.0118, longitude=101.7949)
|
|
69
|
+
print(f"Provider: {res.provider}, Zone: {res.zone}")
|
|
70
|
+
for day in res.prayers[:3]:
|
|
71
|
+
print(f"{day.date} ({day.hijri_full}): Subuh {day.fajr}, Dhuha {day.dhuha}, Zohor {day.dhuhr}")
|
|
72
|
+
|
|
73
|
+
# 2. Fetch by JAKIM Zone code
|
|
74
|
+
zone_res = await client.get_prayer_times(zone="SGR01")
|
|
75
|
+
print(f"SGR01 Day 1 Subuh: {zone_res.prayers[0].fajr}")
|
|
76
|
+
|
|
77
|
+
# 3. Fetch international coordinates (e.g. Makkah -> Aladhan)
|
|
78
|
+
makkah_res = await client.get_prayer_times(latitude=21.4225, longitude=39.8262)
|
|
79
|
+
print(f"Makkah provider: {makkah_res.provider}")
|
|
80
|
+
|
|
81
|
+
# 4. Significant Islamic milestones
|
|
82
|
+
events = await client.get_islamic_events(year=2026)
|
|
83
|
+
for ev in events[:3]:
|
|
84
|
+
print(f"{ev.gregorian_date}: {ev.event_name} ({ev.hijri_date})")
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
asyncio.run(main())
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT © [Zubir Jamal](https://github.com/zubirjamal)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
esolat/__init__.py,sha256=0uPcCagTLzYUXCP-hFDCnuV_pnxorCC3YRlSlx6EzPQ,1078
|
|
2
|
+
esolat/client.py,sha256=I53PUdQ6W0pJPiB2ycoGEc0DXYQsNPhy8fKtgUCYJ_0,19542
|
|
3
|
+
esolat/constants.py,sha256=h-LX6rikNSVheUVjGmmWVuz5aWbn66w0nQAPSKdrvJE,5716
|
|
4
|
+
esolat/exceptions.py,sha256=1E1WYWlU7XO1YWAknZ9bms71SxYCNwIHsvgyec61Jb8,368
|
|
5
|
+
esolat/models.py,sha256=5dMlOEba5RCW2WIrW6a6iQxr0A2RjUuwYQQppjKKDzw,1874
|
|
6
|
+
python_esolat-0.1.0.dist-info/licenses/LICENSE,sha256=-8Gy-Tc4Pvs2SXtHGhGlrbefT3QORXTimp0nJjONhl4,326
|
|
7
|
+
python_esolat-0.1.0.dist-info/METADATA,sha256=d34zrdj3-Rj7TOWoOWYDmI07S9u_zw6KYW_8RWLPuPM,4011
|
|
8
|
+
python_esolat-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
python_esolat-0.1.0.dist-info/top_level.txt,sha256=j3leiMbxcY4w0G86FxiDiJUBpkxx42PrXLioB1nhXoI,7
|
|
10
|
+
python_esolat-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zubir Jamal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to deal in the Software without restriction, subject to the condition that the above copyright notice and this permission notice appear in all copies.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
esolat
|