namaadhu-vaguthu/namaadhuvaguthu.sh

77 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
INPUT=prayer.png
OUTPUT=prayer_added.png
PRAYERTIMES_CSV="male.csv"
DAY_OF_YEAR=$(($(date -d "@$(date +%s)" +%j) - 1))
source .env
rm $OUTPUT > /dev/null
human() {
HOUR="$(( $1 / 60 ))"
if (( $(( $1 / 60 )) < 10 )) ; then
HOUR="0$(( $1 / 60 ))"
fi
MINUTE="$(( $1 % 60 ))"
if (( $(( $1 % 60 )) < 10 )) ; then
MINUTE="0$(( $1 % 60 ))"
fi
echo "$HOUR:$MINUTE"
}
imagemagick(){
TIME=$1
PRAYER=$2
case $PRAYER in
fathis)
POSITION='+685+430'
;;
iruaraa)
POSITION='+440+430'
;;
mendhuru)
POSITION='+220+430'
;;
asr)
POSITION='+685+768'
;;
magrib)
POSITION='+440+768'
;;
isha)
POSITION='+220+768'
esac
if [ -f $OUTPUT ]
then
INPUT=$OUTPUT
fi
echo Prayer=$PRAYER DayOfYear=$DAY_OF_YEAR Time=$TIME File=$INPUT
convert $INPUT \
-font $PWD/CourierPrime.ttf \
-pointsize 48 \
-fill white \
-annotate $POSITION $TIME \
$OUTPUT
}
Fajr=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f2)
Sunrise=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f3)
Dhuhr=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f4)
Asr=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f5)
Maghrib=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f6)
Isha=$(grep "^$DAY_OF_YEAR," $PRAYERTIMES_CSV | cut -d, -f7)
imagemagick $(human $Fajr) fathis
imagemagick $(human $Sunrise) iruaraa
imagemagick $(human $Dhuhr) mendhuru
imagemagick $(human $Asr) asr
imagemagick $(human $Maghrib) magrib
imagemagick $(human $Isha) isha
curl -s -F photo=@$OUTPUT $TG_BOTAPI$TG_BOT_TOKEN/sendphoto?chat_id=$TG_CHATID