-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·128 lines (113 loc) · 3.39 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/sbin/python
import salat as st
import datetime as dt
from datetime import datetime
import time as timeModule
import sys
lat = 30
longg = 31
sunrise = True
timeDiff = 3 # GMT+x
calcMethod = st.CalculationMethod.EGYPT
asrMethod = st.AsrMethod.STANDARD
def getTimeArr(date):
# Arguments:
# Date: date of the targeted day as dt.date(year,month,day)
# lat: latitude of the location
# longg: longitude of the location
# sunrise: add the sunrise to the list of it's true
# timeDiff: UTC+X, it's the X
# calcMethod: prayer calculation method st.CalculationMethod.METHOD
# asrMethod: asr prayer calculation method sr.AsrMethod.STANDARD
# Returns:
# dictionary contains the prayers time of the day as "%I:%M:%S %p"
pt = st.PrayerTimes(calcMethod,asrMethod)
# date = dt.date(2024,2,27)
# lat = 30
# longg = 31
def negativeTimeToDelta(time):
posTime = time % 24
return dt.timedelta(hours=posTime)
timeDelta = negativeTimeToDelta(timeDiff)
zone = dt.timezone(timeDelta)
prayer_times = pt.calc_times(date,zone,longg,lat)
dic = {}
# fajr
# sunrise
# dhuhr
# asr
# maghrib
# isha
for name,time in prayer_times.items():
#newTime = time.strftime("%Y-%m-%d %H:%M:%S")
newTime = datetime.combine(date,time.time())
if sunrise == False:
if name != "sunrise":
#dic[name]= timeModule.strptime(newTime,"%Y-%m-%d %H:%M:%S")
dic[name]= newTime
else:
dic[name] = newTime
return dic
def subTime(now, salah):
# Arguments
# now: The time at this moment
# salah: The time of the salah to calculate the remaining on it
# Returns:
# the difference in seconds
# return (salah - now).total_seconds()
return salah - now
def allSalahTimes():
# Returns:
# dictionary of today's prayer times in a dictionary
# and adds item "nfajr": next Fajr time
today = datetime.today()
tomorrow = today + dt.timedelta(days = 1)
todayTimes = getTimeArr(today)
nextFajr = getTimeArr(tomorrow)['fajr']
# now = datetime.now()
prayers = {}
for name,time in todayTimes.items():
prayers[name] = time
prayers['nfajr'] = nextFajr
return prayers
def nearestSalah(allTimes):
# Returns:
# An array [next salah name, time remain, time, sign]
now = datetime.now()
for name,time in allTimes.items():
diffS = subTime(now,time).total_seconds()
if diffS > (-25 * 60):
sign = " "
if diffS > 0:
sign = "-"
datetimeObj = subTime(now,time) + dt.datetime(2000,1,1,0,0,0,0)
elif diffS < 0:
sign = "+"
datetimeObj = dt.datetime(2000,1,1,0,0,0,0) + dt.timedelta(seconds=abs(diffS))
else:
sign = " "
datetimeObj = dt.datetime(2000,1,1,0,0,0,0) + dt.timedelta(seconds=abs(diffS))
if name == 'nfajr':
name = 'fajr'
return [name,datetimeObj, time, sign]
times = allSalahTimes()
nearestSalahArr = nearestSalah(times)
nearestSalahName = nearestSalahArr[0].capitalize()
nearestSalahRemain = nearestSalahArr[1]
if nearestSalahArr[3] == "+":
nearestSalahTimeStr = nearestSalahRemain.strftime("%M:%S")
else:
nearestSalahTimeStr = nearestSalahRemain.strftime("%H:%M")
# You can combine it with for ur polybar config
sign = nearestSalahArr[3]
if sign == " ":
output = "It's " + nearestSalahName + "!"
else:
output = sign + nearestSalahTimeStr
try:
if sys.argv[1] in ["fajr", "sunrise", "dhuhr", "asr", "maghrib", "isha"]:
print(times[sys.argv[1]].strftime("%I:%M"))
elif sys.argv[1] == "next":
print(nearestSalahName)
except:
print(sign + nearestSalahTimeStr)