namaadhu-vaguthu/namaadhuvaguthu.sh

89 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
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'
COLOR=white
;;
iruaraa)
POSITION='+450+430'
COLOR=white
;;
mendhuru)
POSITION='+215+430'
COLOR=white
;;
asr)
POSITION='+685+768'
COLOR=white
;;
magrib)
POSITION='+450+768'
COLOR=white
;;
isha)
POSITION='+215+768'
COLOR=white
;;
date)
POSITION='+375+190'
TIME=$(date +'%d-%m-%Y')
COLOR='#AC5757'
esac
if [ -f $OUTPUT ]
then
INPUT=$OUTPUT
fi
echo Prayer=$PRAYER DayOfYear=$DAY_OF_YEAR Time=$TIME File=$INPUT Colour=$COLOR
convert $INPUT \
-font $PWD/CourierPrime.ttf \
-pointsize 48 \
-fill $COLOR \
-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
imagemagick "" date
curl -s -F photo=@$OUTPUT $TG_BOTAPI$TG_BOT_TOKEN/sendphoto?chat_id=$TG_CHATID