Skip to content

Commit

Permalink
Merge github.com:achaudhry/adhan into fridaySurahBaqarah
Browse files Browse the repository at this point in the history
Accepted both changes in .gitignore
  • Loading branch information
rehanhaider committed May 11, 2021
2 parents cda62d1 + b6d9738 commit 0d0e7b4
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
*.pyc
adhan.log
settings.ini
__pycache__
__pycache__
.settings
before-hooks.d/*.sh
after-hooks.d/*.sh
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ This projects uses a python script which automatically calculates [adhan](https:
Run this command:

```bash
<<<<<<< HEAD
$ python3 /home/pi/adhan/updateAzaanTimers.py --lat <YOUR_LAT> --lng <YOUR_LNG> --method <METHOD>
=======
$ /home/pi/adhan/updateAzaanTimers.py --lat <YOUR_LAT> --lng <YOUR_LNG> --method <METHOD>
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002
```

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

If everythig worked, your output will look something like this:
```
<<<<<<< HEAD
---------------------------------
Co-ordinates provided
---------------------------------
Expand Down Expand Up @@ -58,6 +63,22 @@ Crob jobs scheduled
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
---------------------------------
=======
20 60 Egypt 0 0
05:51
11:52
14:11
16:30
17:53
51 5 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-fajr.mp3 0 # rpiAdhanClockJob
52 11 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
11 14 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
30 16 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
53 17 * * * /home/pi/adhan/playAzaan.sh /home/pi/adhan/Adhan-Madinah.mp3 0 # rpiAdhanClockJob
0 1 * * * /home/pi/adhan/updateAzaanTimers.py >> /home/pi/adhan/adhan.log 2>&1 # rpiAdhanClockJob
@monthly truncate -s 0 /home/pi/adhan/adhan.log 2>&1 # rpiAdhanClockJob
Script execution finished at: 2017-01-06 21:22:31.512667
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002
```

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.
Expand All @@ -81,11 +102,47 @@ There are 2 additional arguments that are optional, you can set them in the firs
further runs: `--fajr-azaan-volume` and `azaan-volume`. You can control the volume of the Azaan
by supplying numbers in millibels. To get more information on how to select the values, run the command with `-h`.

## Configuring custom actions before/after adhan

Sometimes it is needed to run custom commands either before, after or before
and after playing adhan. For example, if you have
[Quran playing continuously](https://github.com/LintangWisesa/RPi_QuranSpeaker),
you would want to pause and resume the playback. Another example, is to set your
status on a social network, or a calendar, to block/unblock the Internet
using [pi.hole rules](https://docs.pi-hole.net/), ... etc.

You can easily do this by adding scripts in the following directories:
- `before-hooks.d`: Scripts to run before adhan playback
- `after-hooks.d`: Scripts to run after adhan playback

### Example:
To pause/resume Quran playback if using the
[RPi_QuranSpeaker](https://github.com/LintangWisesa/RPi_QuranSpeaker) project, place
the following in 2 new files under the above 2 directories:

```bash
# before-hooks.d/01-pause-quran-speaker.sh
#!/usr/bin/env bash
/home/pi/RPi_QuranSpeaker/pauser.py pause
```

```bash
# after-hooks.d/01-resume-quran-speaker.sh
#!/usr/bin/env bash
/home/pi/RPi_QuranSpeaker/pauser.py resume
```

Do not forget to make the scripts executable:
```bash
chmod u+x ./before-hooks.d/01-pause-quran-speaker.sh
chmod u+x ./after-hooks.d/01-resume-quran-speaker.sh
```

## Tips:
1. You can see your currently scheduled jobs by running `crontab -l`
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`

### Credits
## Credits
I have made modifications / bug fixes but I've used the following as starting point:
* Python code to calculate adhan times: http://praytimes.org/code/
* Basic code to turn the above into an adhan clock: http://randomconsultant.blogspot.co.uk/2013/07/turn-your-raspberry-pi-into-azaanprayer.html
Expand Down
5 changes: 5 additions & 0 deletions after-hooks.d/00-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# This file must be executable, to make it as such, run the following:
# chmod u+x <this-file>
# It can also be written in any language so long as a valid shebang (#!) is used as above
echo "Placeholder for an after hook"
5 changes: 5 additions & 0 deletions before-hooks.d/00-example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# This file must be executable, to make it as such, run the following:
# chmod u+x <this-file>
# It can also be written in any language so long as a valid shebang (#!) is used as above
echo "Placeholder for a before hook"
24 changes: 24 additions & 0 deletions playAzaan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
if [ $# -lt 1 ]; then
echo "USAGE: $0 <azaan-audio-path> [<volume>]"
exit 1
fi

audio_path="$1"
vol=${2:-0}
root_dir=`dirname $0`

# Run before hooks
for hook in $root_dir/before-hooks.d/*; do
echo "Running before hook: $hook"
$hook
done

# Play Azaan audio
omxplayer --vol $vol -o local $audio_path

# Run after hooks
for hook in $root_dir/after-hooks.d/*; do
echo "Running after hook: $hook"
$hook
done
10 changes: 9 additions & 1 deletion updateAzaanTimers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import datetime
import time
Expand Down Expand Up @@ -165,12 +165,20 @@ def addClearLogsCronJob (objCronTab, strCommand):
isDst = time.localtime().tm_isdst

now = datetime.datetime.now()
<<<<<<< HEAD
strPlayFajrAzaanMP3Command = f"omxplayer --vol {fajr_azaan_vol} -o local {root_dir}/media/Adhan-fajr.mp3 > /dev/null 2>&1"
strPlayAzaanMP3Command = f"omxplayer --vol {default_azaan_vol} -o local {root_dir}/media/Adhan-Makkah1.mp3 > /dev/null 2>&1"
strUpdateCommand = f"python {root_dir}/updateAzaanTimers.py >> {root_dir}/adhan.log 2>&1"
strClearLogsCommand = f"truncate -s 0 {root_dir}/adhan.log 2>&1"
strJobComment = "rpiAdhanClockJob"
strSurahBaqarahMP3Command = f"omxplayer --vol {surahVolume} -o local {root_dir}/media/002-surah-baqarah-mishary.mp3 > /dev/null 2>&1"
=======
strPlayFajrAzaanMP3Command = '{}/playAzaan.sh {}/Adhan-fajr.mp3 {}'.format(root_dir, root_dir, fajr_azaan_vol)
strPlayAzaanMP3Command = '{}/playAzaan.sh {}/Adhan-Madinah.mp3 {}'.format(root_dir, root_dir, azaan_vol)
strUpdateCommand = '{}/updateAzaanTimers.py >> {}/adhan.log 2>&1'.format(root_dir, root_dir)
strClearLogsCommand = 'truncate -s 0 {}/adhan.log 2>&1'.format(root_dir)
strJobComment = 'rpiAdhanClockJob'
>>>>>>> b6d9738f886eaea16e056449693b338c441ea002

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

0 comments on commit 0d0e7b4

Please # to comment.