Created
April 1, 2016 10:59
-
-
Save j3itch/ca719388b232dc44b98433a44353b7bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import decimal | |
import json | |
import requests | |
try: | |
# python2 sucks | |
input = raw_input | |
except NameError: | |
pass | |
URL = "https://www2.my.commbank.com.au/mobile/t/ajaxcalls.aspx" | |
def paramify(params): | |
return {"Params": [{"Name": k, "Value": v} for k, v in params.items()]} | |
def numerify(a): | |
sign = -1 if a[-2:] == "DR" else 1 | |
return decimal.Decimal(a[1:-2].replace(",", "")) * sign | |
def get_commbank_info(username, password, token=""): | |
r = requests.post( | |
URL, headers={"content-type": "application/json"}, | |
data=json.dumps(paramify({ | |
"Request": "login", | |
"UserName": username, | |
"Password": password, | |
"Token": token, | |
"AccountIds": "1,2,3,4,5,6"}))) | |
r.raise_for_status() | |
body = json.loads(r.text[2:-2]) | |
if body["ErrorMessages"]: | |
raise ValueError(body["ErrorMessages"]) | |
return body | |
if __name__ == "__main__": | |
import getpass | |
username = input("Username: ") | |
password = getpass.getpass() | |
print("Your balances:") | |
tx = get_commbank_info(username, password) | |
for account in tx['RecentTransactions']['Accounts']: | |
print("{}: {}".format(account['AccountName'], | |
numerify(account['Balance']))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment