namaadhu-vaguthu/namaadhuvaguthu.sh

91 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
2022-09-13 19:43:39 +05:00
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
2022-09-13 19:28:19 +05:00
INPUT=prayer.png
OUTPUT=prayer_added.png
PRAYERTIMES_CSV="male.csv"
2023-02-08 11:05:27 +05:00
#DAY_OF_YEAR=$(($(date -d "@$(date +%s)" +%j) - 1)) # no clue why this wasnt whats below from the begning
#DAY_OF_YEAR=$(date +%j) # this adds a zero at the begining and causes issues
DAY_OF_YEAR=$((10#$(date +%j))) # remove the zero https://stackoverflow.com/a/11130324
2022-09-09 13:49:17 +05:00
source .env
2022-09-09 11:28:03 +05:00
rm $OUTPUT > /dev/null
2022-09-09 11:28:03 +05:00
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"
2022-09-09 11:28:03 +05:00
}
imagemagick(){
TIME=$1
PRAYER=$2
case $PRAYER in
fathis)
2022-09-09 03:45:04 +05:00
POSITION='+685+430'
2022-09-13 19:28:19 +05:00
COLOR=white
;;
iruaraa)
2022-09-13 19:28:19 +05:00
POSITION='+450+430'
COLOR=white
;;
mendhuru)
2022-09-13 19:28:19 +05:00
POSITION='+215+430'
COLOR=white
;;
asr)
2022-09-09 03:45:04 +05:00
POSITION='+685+768'
2022-09-13 19:28:19 +05:00
COLOR=white
;;
magrib)
2022-09-13 19:28:19 +05:00
POSITION='+450+768'
COLOR=white
;;
isha)
2022-09-13 19:28:19 +05:00
POSITION='+215+768'
COLOR=white
2022-09-13 18:58:40 +05:00
;;
date)
2022-09-13 19:28:19 +05:00
POSITION='+375+190'
TIME=$(date +'%d-%m-%Y')
COLOR='#AC5757'
esac
if [ -f $OUTPUT ]
then
INPUT=$OUTPUT
fi
2022-09-13 19:28:19 +05:00
echo Prayer=$PRAYER DayOfYear=$DAY_OF_YEAR Time=$TIME File=$INPUT Colour=$COLOR
convert $INPUT \
2022-09-09 03:45:04 +05:00
-font $PWD/CourierPrime.ttf \
-pointsize 48 \
2022-09-13 19:28:19 +05:00
-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)
2022-09-13 18:58:40 +05:00
imagemagick $(human $Fajr) fathis
imagemagick $(human $Sunrise) iruaraa
imagemagick $(human $Dhuhr) mendhuru
imagemagick $(human $Asr) asr
imagemagick $(human $Maghrib) magrib
imagemagick $(human $Isha) isha
2022-09-13 18:58:40 +05:00
imagemagick "" date
2022-09-09 03:45:04 +05:00
2022-09-09 13:47:53 +05:00
curl -s -F photo=@$OUTPUT $TG_BOTAPI$TG_BOT_TOKEN/sendphoto?chat_id=$TG_CHATID