-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_prayer.py
42 lines (33 loc) · 1.27 KB
/
read_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
34
35
36
37
38
39
40
41
42
import re
from crontab import CronTab
def read_prayer_times(file_path):
prayer_times = []
with open(file_path, "r") as file:
for line in file:
match = re.match(r"Prayer (\d+): \d{4}-\d{2}-\d{2} (\d{2}:\d{2}):\d{2}", line)
if match:
prayer_index = int(match.group(1))
if prayer_index != 1: # Exclude Prayer 1
prayer_time_str = match.group(2)
prayer_times.append((prayer_index, prayer_time_str))
return prayer_times
def add_cron_jobs(prayer_times):
cron = CronTab(user='CHANGE_ME')
# Remove existing prayer time jobs
cron.remove_all(comment="Prayer Time")
for prayer_index, prayer_time_str in prayer_times:
prayer_hour, prayer_minute = map(int, prayer_time_str.split(':'))
if prayer_index == 0:
audio_file = "azan2.mp3"
else:
audio_file = "azan.mp3"
command = f"mpg123 {audio_file}"
job = cron.new(command=command, comment="Prayer Time")
job.setall(prayer_minute, prayer_hour, '*', '*', '*')
cron.write()
def main():
file_path = "prayer.txt" # Path to prayer.txt
prayer_times = read_prayer_times(file_path)
add_cron_jobs(prayer_times)
if __name__ == "__main__":
main()