-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck-athan
More file actions
executable file
·40 lines (31 loc) · 1.2 KB
/
Copy pathcheck-athan
File metadata and controls
executable file
·40 lines (31 loc) · 1.2 KB
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
#!/usr/bin/python
import urllib.request
import json
import datetime
def convert_time(time, convert_from, convert_to):
return datetime.datetime.strptime(time, convert_from).time().strftime(convert_to)
url = 'http://api.aladhan.com/timingsByCity?city=Cumberland&country=MD&method=2'
with urllib.request.urlopen(url) as response:
html = response.read()
convert_from = "%H:%M"
wanted_time_format = "%I:%M %p"
timings = json.loads(html)['data']['timings']
del timings['Sunset']
del timings['Imsak']
del timings['Midnight']
current_time = datetime.datetime.now().time()
for name, time in timings.items():
datetimed = datetime.datetime.strptime(timings[name], convert_from).time()
if current_time >= datetimed:
current_prayer = [name, convert_time(
time, convert_from, wanted_time_format)]
else:
current_prayer = ['Isha', 'Anytime']
if current_time <= datetimed:
next_prayer = [name, convert_time(
time, convert_from, wanted_time_format)]
break
print("{0} {1} : {2} {3}".format(current_prayer[0],
current_prayer[1],
next_prayer[0],
next_prayer[1]))