From b9bb5db4e274d3d1a327ddd77512cabe1cb8a3f1 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Sun, 19 Sep 2021 20:14:44 +0500 Subject: [PATCH] i forgot --- bml-tg-notify.sh | 92 +++++++++++++++++++++++++++++++++---------- bml-tg-notify.sh.save | 0 env.sample | 2 +- readaccounts.sh | 12 ++++++ 4 files changed, 84 insertions(+), 22 deletions(-) create mode 100644 bml-tg-notify.sh.save create mode 100644 readaccounts.sh diff --git a/bml-tg-notify.sh b/bml-tg-notify.sh index e86607d..460f0f1 100755 --- a/bml-tg-notify.sh +++ b/bml-tg-notify.sh @@ -10,9 +10,26 @@ fi } login(){ +echo "" +echo "" +echo =========== +echo LOGGING IN curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} # attempt to login and generate cookie +echo "" +echo "" +echo =========== +echo SELECTING PROFILE PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1) ; echo $PROFILE # get Personal Profile curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE # select Personal Profile +echo "" +echo "" +} + +getnumberofaccounts(){ +NUMBEROFACCOUNTS=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | wc -l) +NUMBEROFACCOUNTS=$(expr $NUMBEROFACCOUNTS - 1) +echo "" +echo $NUMBEROFACCOUNTS Accounts loaded } getaccountdetails(){ @@ -23,14 +40,28 @@ CURRENCY=$(echo $REQACCOUNTDETAILS | jq -r .currency) } send_tg(){ -TGTEXT=$(echo $DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram +TGTEXT=$(echo $ACCOUNTTYPE%0A$ACCOUNTNUMBER%0A%0A$DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram +echo "" +echo "" +echo SENDING TO TG + curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT #send to telegram -echo "Next check in $DELAY seconds" +echo "" +echo "" + } req_history(){ +echo "" +echo "" +echo =========== +echo Requesting History for: $BML_ACCOUNTID REQ_HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today) ; echo $REQ_HISTORY -LOGIN_STATUS=$(echo $REQ_HISTORY | jq -r .success) ; echo $LOGIN_STATUS +#LOGIN_STATUS=$(echo $REQ_HISTORY | jq -r .success) ; echo $LOGIN_STATUS +echo "" +echo "" +echo =========== + } check_diff(){ @@ -44,26 +75,33 @@ read_delay(){ DELAY=$(cat delay) ; echo $DELAY # read delay file and get value } -echo_delay(){ -echo "Nothing new....Next check in $DELAY seconds" -} init login -getaccountdetails loop(){ -while true; do +i=0 +# if [ "$LOGIN_STATUS" != "true" ] +# then +# echo "" +# echo "" +# echo " LOGGED OUT - SLEEPING +# sleep 200 +# login +# infinite_loop +# fi -req_history - -if [ "$LOGIN_STATUS" != "true" ] -then - login - break & loop -fi - -check_diff -read_delay + for account in `cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'"` + do + accountid[$i]=$account; + i=$(($i+1)); + BML_ACCOUNTID=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | head -n$i | tail -n1) + echo "" + echo $BML_ACCOUNTID Selected + echo "" + getaccountdetails + req_history + check_diff + read_delay if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history then @@ -72,7 +110,13 @@ then echo "=============" ; echo NEW DAY ; echo "=============" # curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=GO%20TO%20SLEEP%0AITS%0000 else + echo "" + echo "" + echo ============== + echo History of $ACCOUNTTYPE - $ACCOUNTNUMBER echo $HISTORY | jq + echo "" + echo "" DESCRIPTION=$(echo $HISTORY | jq -r .description | head -n1) ; echo $DESCRIPTION # get last trascation description AMOUNT=$(echo $HISTORY | jq -r .amount | head -n1) ; echo $AMOUNT # get last trascation amount if [ "$DESCRIPTION" = "Transfer Credit" ] # if last trascation is description is Transfer Credit @@ -95,9 +139,15 @@ then send_tg fi else - echo_delay + echo "Nothing new....Next check in $DELAY seconds" fi -sleep $DELAY # initiate delay read from delay file done } -loop + +infinite_loop(){ +while true; do + loop + sleep $DELAY # initiate delay read from delay file +done +} +infinite_loop diff --git a/bml-tg-notify.sh.save b/bml-tg-notify.sh.save new file mode 100644 index 0000000..e69de29 diff --git a/env.sample b/env.sample index 90fcad4..3065180 100644 --- a/env.sample +++ b/env.sample @@ -7,6 +7,6 @@ TG_BOT_TOKEN='' #Your Telegram Bot API Token, Contact @BotFather on Telegram to TG_CHATID='' #Your Telegram chat ID, This could be your user, group, supergroup or channel ID, add "-100" first if supergroup or channel # DO NOT EDIT THESE UNLESS YOU KNOW WHAT YOURE DOING -COOKIE=.cache/cookie #No need to change +COOKIE=.cache/cookie TG_BOTAPI='https://api.telegram.org/bot' BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' diff --git a/readaccounts.sh b/readaccounts.sh new file mode 100644 index 0000000..790dceb --- /dev/null +++ b/readaccounts.sh @@ -0,0 +1,12 @@ +#!/bin/bash +NUMBEROFACCOUNTS=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | wc -l) +i=0; +for account in `cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'"` +do + accountid[$i]=$account; + i=$(($i+1)); +SELECT=$(cat .env | grep BML_ACCOUNTID | cut --complement -d "'" -f 1 | cut -f1 -d "'" | head -n$i | tail -n1) +echo $SELECT Selected +sleep 1 +i=0 +done