-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_prayer.py
33 lines (27 loc) · 1023 Bytes
/
fetch_prayer.py
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
import requests
from datetime import datetime
def fetch_prayer_times(url):
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
prayer_times = data['response']['times']
return prayer_times
except requests.exceptions.RequestException as e:
print("An error occurred while fetching prayer times:", e)
return []
def write_to_file(prayer_times):
with open("prayer.txt", "w") as file:
for idx, prayer_time in enumerate(prayer_times):
prayer_datetime = datetime.fromtimestamp(prayer_time)
formatted_time = prayer_datetime.strftime("%Y-%m-%d %H:%M:%S")
file.write(f"Prayer {idx}: {formatted_time}\n")
def main():
fetch_url = "https://mpt.i906.my/mpt.json?code=wlp-0&filter=1"
prayer_times = fetch_prayer_times(fetch_url)
if not prayer_times:
print("No prayer times fetched.")
return
write_to_file(prayer_times)
if __name__ == "__main__":
main()