sarmic/bml-tg-notify/bml-tg-notify.sh

37 lines
1.2 KiB
Bash
Raw Normal View History

2021-05-12 06:07:11 +05:00
#!/bin/bash
2021-05-12 06:53:43 +05:00
source .env
2021-05-12 07:08:31 +05:00
mkdir -p ~/.cache/bml-cli/
2021-05-12 06:07:11 +05:00
TG_BOTAPI='https://api.telegram.org/bot'
BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api'
COOKIE=~/.cache/bml-cli/cookie
2021-05-12 06:35:36 +05:00
LOGIN=$(curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} | jq -r .code)
2021-05-12 06:07:11 +05:00
if [ "$LOGIN" = "0" ]
then
2021-05-12 06:35:36 +05:00
PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1)
curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE > /dev/null
2021-05-12 06:07:11 +05:00
else
echo Something went wrong
exit
fi
2021-05-12 06:35:36 +05:00
2021-05-12 06:07:11 +05:00
while true; do
2021-05-12 07:08:31 +05:00
2021-05-12 06:07:11 +05:00
CHECKDIFF1=$(echo $HISTORY | wc -c)
HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]')
2021-05-12 06:25:45 +05:00
CHECKDIFF2=$(echo $HISTORY | wc -c)
2021-05-12 07:08:31 +05:00
2021-05-12 06:07:11 +05:00
if [ "$CHECKDIFF1" = "$CHECKDIFF2" ]
then
echo nothing new..checking again
else
TRANSFERAMOUNT=$(echo $HISTORY | jq -r .amount | head -n1)
TRANFERFROM=$(echo $HISTORY | jq -r .narrative3 | head -n1)
2021-05-12 06:51:15 +05:00
echo From: $TRANFERFROM
echo MVR: $TRANSFERAMOUNT
2021-05-12 06:07:11 +05:00
TRANFERFROM=`echo "$TRANFERFROM" | sed "s/ /%20/"`
2021-05-12 06:51:15 +05:00
curl -s ''${TG_BOTAPI}''${TG_BOT_TOKEN}'/sendMessage?chat_id='${TG_CHATID}'&text=From:%20'${TRANFERFROM}%0A'MVR:%20'${TRANSFERAMOUNT}'' > /dev/null
2021-05-12 06:07:11 +05:00
fi
2021-05-12 06:53:43 +05:00
sleep $SLEEP
2021-05-12 06:07:11 +05:00
done