Skip to content

Instantly share code, notes, and snippets.

@Dharisd
Created May 12, 2021 09:11
Show Gist options
  • Save Dharisd/f4ef075a7e84d85dbb2045f41fc2aa36 to your computer and use it in GitHub Desktop.
Save Dharisd/f4ef075a7e84d85dbb2045f41fc2aa36 to your computer and use it in GitHub Desktop.
import requests
import time
import json
import os
BML_URL ="https://www.bankofmaldives.com.mv/internetbanking/api"
TG_URL = "https://api.telegram.org/bot"
TG_TOKEN = os.getenv("TG_TOKEN")
TG_CHATID = os.getenv("TG_CHATID")
BML_USERNAME = os.getenv("BML_USERNAME")
BML_PASSWORD = os.getenv("BML_PASSWORD")
BML_ACCOUNTID = os.getenv("BML_ACCOUNTID")
BML_ACCOUNTID = os.getenv("BML_DELAY")
old_transactions = []
while True:
session = requests.Session()
login_attempt = session.post(f"{BML_URL}/login",data={"username":BML_USERNAME,"password":BML_PASSWORD}).json()
if login_attempt["success"]:
#get and set the profile
profile = session.get(f"{BML_URL}/profile").json()["payload"]["profile"][0]["profile"]
session.get(f"{BML_URL}/profile",data={"profile":profile})
#get new transactions
transactions = session.get(f"{BML_URL}/account/{BML_ACCOUNTID}/history/today").json()["payload"]["history"]
diff = len(transactions) - len(old_transactions)
if diff != 0:
#send all new tx info to tg
for i in range(len(transactions) -diff,len(transactions)):
text = f"New transaction of MVR {transactions[i]['amount']} from {transactions[i]['narrative3']}"
session.get(f"{TG_URL}{TG_TOKEN}/sendMessage?chat_id={TG_CHATID}&text={text}")
old_transactions = transactions
else:
print(login_attempt["message"])
time.sleep(BML_DELAY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment