does it work? yes, can you explain how? no
This commit is contained in:
		| @@ -1,17 +1,63 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
| source .env # import credentials, tg api, cookie path, bml api | source .env # import credentials, tg api, cookie path, bml api | ||||||
|  |  | ||||||
|  |  | ||||||
|  | init(){ | ||||||
| if [ ! -f delay ] # if delay file missing | if [ ! -f delay ] # if delay file missing | ||||||
| then | then | ||||||
| 	echo 160 > delay # make delay file with 160 sec | 	echo 160 > delay # make delay file with 160 sec | ||||||
| fi | fi | ||||||
| while true; do | } | ||||||
|  |  | ||||||
|  | login(){ | ||||||
| curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD}  # attempt to login and generate cookie | curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD}  # attempt to login and generate cookie | ||||||
| PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1) ; echo $PROFILE # get Personal 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 | curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE  # select Personal Profile | ||||||
|  | } | ||||||
|  |  | ||||||
|  | send_tg(){ | ||||||
|  | TGTEXT=$(echo $DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram | ||||||
|  | curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT  #send to telegram | ||||||
|  | echo  "Next check in $DELAY seconds" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | req_history(){ | ||||||
|  | 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 | ||||||
|  | } | ||||||
|  |  | ||||||
|  | check_diff(){ | ||||||
| CHECKDIFF1=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF1 # check intial and previous history | CHECKDIFF1=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF1 # check intial and previous history | ||||||
| HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]') ; echo $HISTORY # request history | #HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]') ; echo $HISTORY # request history | ||||||
|  | HISTORY=$(echo $REQ_HISTORY | jq -r '.payload | .history | .[]') ; echo $HISTORY | ||||||
| CHECKDIFF2=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF2 # check new history | CHECKDIFF2=$(echo $HISTORY | wc -c) ; echo $CHECKDIFF2 # check new history | ||||||
|  | } | ||||||
|  |  | ||||||
|  | read_delay(){ | ||||||
| DELAY=$(cat delay) ; echo $DELAY # read delay file and get value | DELAY=$(cat delay) ; echo $DELAY # read delay file and get value | ||||||
|  | } | ||||||
|  |  | ||||||
|  | echo_delay(){ | ||||||
|  | echo  "Nothing new....Next check in $DELAY seconds" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | init | ||||||
|  | login | ||||||
|  |  | ||||||
|  | loop(){ | ||||||
|  | while true; do | ||||||
|  |  | ||||||
|  | req_history | ||||||
|  |  | ||||||
|  | if [ "$LOGIN_STATUS" != "true" ] | ||||||
|  | then | ||||||
|  | 	login | ||||||
|  | 	break & loop | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | check_diff | ||||||
|  | read_delay | ||||||
|  |  | ||||||
| if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history | if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] # if previous history do not match with new history | ||||||
| then | then | ||||||
| 	if [ "$CHECKDIFF2" = "1" ] | 	if [ "$CHECKDIFF2" = "1" ] | ||||||
| @@ -30,7 +76,7 @@ then | |||||||
| 		then | 		then | ||||||
| 			FROMTOAT=To | 			FROMTOAT=To | ||||||
| 			ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) ; echo $ENTITY # get last person or place name | 			ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) ; echo $ENTITY # get last person or place name | ||||||
| 		elif [ "$DESCRIPTION" = "ATM Withdrawal" ] || [ "$DESCRIPTION" = "Purchase" ] # if last trascation descripton is ATM Withdrawal | 		elif [ "$DESCRIPTION" = "Cash Deposit-ATM" ] [ "$DESCRIPTION" = "ATM Withdrawal" ] || [ "$DESCRIPTION" = "Purchase" ] # if last trascation descripton is ATM Withdrawal | ||||||
| 		then | 		then | ||||||
| 			FROMTOAT=At | 			FROMTOAT=At | ||||||
| 			ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) ; echo $ENTITY #get last ATM name | 			ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) ; echo $ENTITY #get last ATM name | ||||||
| @@ -39,14 +85,12 @@ then | |||||||
| 			FROMTOAT=From | 			FROMTOAT=From | ||||||
| 			ENTITY=$(echo $HISTORY | jq -r .narrative2 | head -n1) ; echo $ENTITY # get last trascation company name | 			ENTITY=$(echo $HISTORY | jq -r .narrative2 | head -n1) ; echo $ENTITY # get last trascation company name | ||||||
| 		fi | 		fi | ||||||
| 		TGTEXT=$(echo $DESCRIPTION%0A$FROMTOAT: $ENTITY%0A$CURRENCY: $AMOUNT | sed "s/ /%20/g") ; echo $TGTEXT # format text for telegram | 		send_tg | ||||||
| 		curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT  #send to telegram |  | ||||||
| 		echo  "Next check in $DELAY seconds" |  | ||||||
| 		unset DESCRIPTION ; unset AMOUNT ; unset FROMTOAT ; unset ENTITY ; unset TGTEXT |  | ||||||
| 	fi | 	fi | ||||||
| else | else | ||||||
|  | 	echo_delay | ||||||
| 	echo "nothing new..checking again in $DELAY seconds" |  | ||||||
| fi | fi | ||||||
| sleep $DELAY # initiate delay read from delay file | sleep $DELAY # initiate delay read from delay file | ||||||
| done | done | ||||||
|  | } | ||||||
|  | loop | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user