Skip to content

Commit 0d0e7b4

Browse files
committed
Merge github.com:achaudhry/adhan into fridaySurahBaqarah
Accepted both changes in .gitignore
2 parents cda62d1 + b6d9738 commit 0d0e7b4

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
*.pyc
44
adhan.log
55
settings.ini
6-
__pycache__
6+
__pycache__
7+
.settings
8+
before-hooks.d/*.sh
9+
after-hooks.d/*.sh

README.md

+58-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ This projects uses a python script which automatically calculates [adhan](https:
2222
Run this command:
2323

2424
```bash
25+
<<<<<<< HEAD
2526
$ python3 /home/pi/adhan/updateAzaanTimers.py --lat <YOUR_LAT> --lng <YOUR_LNG> --method <METHOD>
27+
=======
28+
$ /home/pi/adhan/updateAzaanTimers.py --lat <YOUR_LAT> --lng <YOUR_LNG> --method <METHOD>
29+
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002
2630
```
2731

2832
Replace the arguments above with your location information and calculation method:
@@ -31,6 +35,7 @@ Replace the arguments above with your location information and calculation metho
3135

3236
If everythig worked, your output will look something like this:
3337
```
38+
<<<<<<< HEAD
3439
---------------------------------
3540
Co-ordinates provided
3641
---------------------------------
@@ -58,6 +63,22 @@ Crob jobs scheduled
5863
0 8 * * 5 omxplayer --vol 0 -o local /home/pi/Desktop/Github/adhan/media/002-surah-baqarah-mishary.mp3 > /dev/null 2>&1 # Surah Baqarah
5964
---------------------------------
6065
66+
=======
67+
20 60 Egypt 0 0
68+
05:51
69+
11:52
70+
14:11
71+
16:30
72+
17:53
73+
51 5 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-fajr.mp3 0 # rpiAdhanClockJob
74+
52 11 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
75+
11 14 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
76+
30 16 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
77+
53 17 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
78+
0 1 * * * /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1 # rpiAdhanClockJob
79+
@monthly truncate -s 0 /home/pi/adhan/adhan.log 2>&1 # rpiAdhanClockJob
80+
Script execution finished at: 2017-01-06 21:22:31.512667
81+
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002
6182
```
6283

6384
If you look at the last few lines, you'll see that 5 adhan times have been scheduled. Then there is another line at the end which makes sure that at 1am every day the same script will run and calculate adhan times for that day. And lastly, there is a line to clear logs on a monthly basis so that your log file doesn't grow too big.
@@ -81,11 +102,47 @@ There are 2 additional arguments that are optional, you can set them in the firs
81102
further runs: `--fajr-azaan-volume` and `azaan-volume`. You can control the volume of the Azaan
82103
by supplying numbers in millibels. To get more information on how to select the values, run the command with `-h`.
83104

105+
## Configuring custom actions before/after adhan
106+
107+
Sometimes it is needed to run custom commands either before, after or before
108+
and after playing adhan. For example, if you have
109+
[Quran playing continuously](https://github.com/LintangWisesa/RPi_QuranSpeaker),
110+
you would want to pause and resume the playback. Another example, is to set your
111+
status on a social network, or a calendar, to block/unblock the Internet
112+
using [pi.hole rules](https://docs.pi-hole.net/), ... etc.
113+
114+
You can easily do this by adding scripts in the following directories:
115+
- `before-hooks.d`: Scripts to run before adhan playback
116+
- `after-hooks.d`: Scripts to run after adhan playback
117+
118+
### Example:
119+
To pause/resume Quran playback if using the
120+
[RPi_QuranSpeaker](https://github.com/LintangWisesa/RPi_QuranSpeaker) project, place
121+
the following in 2 new files under the above 2 directories:
122+
123+
```bash
124+
# before-hooks.d/01-pause-quran-speaker.sh
125+
#!/usr/bin/env bash
126+
/home/pi/RPi_QuranSpeaker/pauser.py pause
127+
```
128+
129+
```bash
130+
# after-hooks.d/01-resume-quran-speaker.sh
131+
#!/usr/bin/env bash
132+
/home/pi/RPi_QuranSpeaker/pauser.py resume
133+
```
134+
135+
Do not forget to make the scripts executable:
136+
```bash
137+
chmod u+x ./before-hooks.d/01-pause-quran-speaker.sh
138+
chmod u+x ./after-hooks.d/01-resume-quran-speaker.sh
139+
```
140+
84141
## Tips:
85142
1. You can see your currently scheduled jobs by running `crontab -l`
86143
2. The output of the job that runs at 1am every night is being captured in `/home/pi/adhan/adhan.log`. This way you can keep track of all successful runs and any potential issues. This file will be truncated at midnight on the forst day of each month. To view the output type `$ cat /home/pi/adhan/adhan.log`
87144

88-
### Credits
145+
## Credits
89146
I have made modifications / bug fixes but I've used the following as starting point:
90147
* Python code to calculate adhan times: http://praytimes.org/code/
91148
* Basic code to turn the above into an adhan clock: http://randomconsultant.blogspot.co.uk/2013/07/turn-your-raspberry-pi-into-azaanprayer.html

after-hooks.d/00-example.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# This file must be executable, to make it as such, run the following:
3+
# chmod u+x <this-file>
4+
# It can also be written in any language so long as a valid shebang (#!) is used as above
5+
echo "Placeholder for an after hook"

before-hooks.d/00-example.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# This file must be executable, to make it as such, run the following:
3+
# chmod u+x <this-file>
4+
# It can also be written in any language so long as a valid shebang (#!) is used as above
5+
echo "Placeholder for a before hook"

playAzaan.sh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
if [ $# -lt 1 ]; then
3+
echo "USAGE: $0 <azaan-audio-path> [<volume>]"
4+
exit 1
5+
fi
6+
7+
audio_path="$1"
8+
vol=${2:-0}
9+
root_dir=`dirname $0`
10+
11+
# Run before hooks
12+
for hook in $root_dir/before-hooks.d/*; do
13+
echo "Running before hook: $hook"
14+
$hook
15+
done
16+
17+
# Play Azaan audio
18+
omxplayer --vol $vol -o local $audio_path
19+
20+
# Run after hooks
21+
for hook in $root_dir/after-hooks.d/*; do
22+
echo "Running after hook: $hook"
23+
$hook
24+
done

updateAzaanTimers.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import datetime
44
import time
@@ -165,12 +165,20 @@ def addClearLogsCronJob (objCronTab, strCommand):
165165
isDst = time.localtime().tm_isdst
166166

167167
now = datetime.datetime.now()
168+
<<<<<<< HEAD
168169
strPlayFajrAzaanMP3Command = f"omxplayer --vol {fajr_azaan_vol} -o local {root_dir}/media/Adhan-fajr.mp3 > /dev/null 2>&1"
169170
strPlayAzaanMP3Command = f"omxplayer --vol {default_azaan_vol} -o local {root_dir}/media/Adhan-Makkah1.mp3 > /dev/null 2>&1"
170171
strUpdateCommand = f"python {root_dir}/updateAzaanTimers.py >> {root_dir}/adhan.log 2>&1"
171172
strClearLogsCommand = f"truncate -s 0 {root_dir}/adhan.log 2>&1"
172173
strJobComment = "rpiAdhanClockJob"
173174
strSurahBaqarahMP3Command = f"omxplayer --vol {surahVolume} -o local {root_dir}/media/002-surah-baqarah-mishary.mp3 > /dev/null 2>&1"
175+
=======
176+
strPlayFajrAzaanMP3Command = '{}/playAzaan.sh {}/Adhan-fajr.mp3 {}'.format(root_dir, root_dir, fajr_azaan_vol)
177+
strPlayAzaanMP3Command = '{}/playAzaan.sh {}/Adhan-Madinah.mp3 {}'.format(root_dir, root_dir, azaan_vol)
178+
strUpdateCommand = '{}/updateAzaanTimers.py >> {}/adhan.log 2>&1'.format(root_dir, root_dir)
179+
strClearLogsCommand = 'truncate -s 0 {}/adhan.log 2>&1'.format(root_dir)
180+
strJobComment = 'rpiAdhanClockJob'
181+
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002
174182

175183
# Remove existing jobs created by this script
176184
system_cron.remove_all(comment=strJobComment)

0 commit comments

Comments
 (0)