skip to Main Content

I love receiving a text message every morning from Chase Bank containing the balance of my checking account. I dove into my personal account settings to see if I could schedule a message to be sent to me with the other account balances on my account, only to realize that checking was the only account this was possible with.

Using a library called mintapi (https://github.com/mrooney/mintapi), I was able to scrape the account data living in my Mint account. The goal is to send a text message through Twillio with the balance of every single account in my Mint account every single morning.

$ mintapi [email: String] [password: String] --accounts

Running the command above in your terminal returns the following object for each financial account I have in Mint:

{
    "linkedAccountId": null,
    "addAccountDate": Int,
    "fiLoginDisplayName": Str,
    "dueDate": "12/27/2017",
    "isTerminal": true,
    "linkCreationTime": null,
    "isActive": true,
    "lastUpdated": Int,
    "rateType": 2,
    "fiName": Str,
    "origAmount": null,
    "klass": "loan",
    "accountTypeInt": 6,
    "id": 9856811,
    "fiLoginId": 3914975,
    "accountType": "loan",
    "currentBalance": Int,
    "fiLoginStatus": "OK",
    "origDate": "02/27/2020",
    "linkStatus": "NOT_LINKED",
    "accountId": Int,
    "yodleeAccountId": Int,
    "name": Str (Account Nickname),
    "status": "1",
    "accountName": Str (Account Name, e.g. Chase Checking),
    "ccAggrStatus": 0,
    "exclusionType": "0",
    "linkedAccount": null,
    "isHiddenFromPlanningTrends": true,
    "accountStatus": "1",
    "accountSystemStatus": "ACTIVE",
    "fiLastUpdated": Int,
    "yodleeAccountNumberLast4": "Int",
    "isError": false,
    "isAccountNotFound": false,
    "rate": null,
    "possibleLinkAccounts": [],
    "lastUpdatedInString": "12 hours",
    "currency": "USD",
    "term": 100,
    "isHostAccount": false,
    "value": Int (Confidential - Account Balance),
    "usageType": null,
    "interestRate": null,
    "isAccountClosedByMint": false,
    "userName": null,
    "yodleeName": Str,
    "closeDate": Int,
    "dueAmt": Int (Confidential - Amount due on next bill),
    "amountDue": 0.0,
    "isClosed": false,
    "fiLoginUIStatus": "OK",
    "addAccountDateInDate": "2017-06-11 13:54:06",
    "closeDateInDate": "2018-03-30 08:21:39",
    "fiLastUpdatedInDate": "2018-03-31 05:33:47",
    "lastUpdatedInDate": "2018-03-31 05:33:47"
  }

What I would like to do is capture the output from the bash script above, and store it as JSON data in a python variable.

Edit: Since asking the question, I have discovered the subprocess library.

import subprocess
out = subprocess.run("mintapi 'email' '******' --accounts", shell=True)

Now, my return value is:

CompletedProcess(args="mintapi 'email' '*******' --accounts", returncode=0)

2

Answers


  1. Oh! It took me a while before I finally understood the question, whoops.
    Twilio have API documentation for sending a message and even a Python library with example code. The two links should be enough to help you with this, good luck.

    EDIT

    Try using subprocess.getoutput() (https://docs.python.org/3/library/subprocess.html#subprocess.getoutput)
    You could then (probably) combine this with ast.literal_eval() as such

    import ast
    import subprocess
    out = subprocess.getoutput("mintapi 'email' '******' --accounts")
    output = ast.literal_eval(out)
    

    Then output would end up being the data you need 🙂

    Login or Signup to reply.
  2. Solution by OP.

    import mintapi
    import subprocess
    import json
    import getpass
    
    mint_user = input('Please enter your Mint login email: ')
    mint_pass = getpass.getpass('Please enter your Mint password: ')
    
    # Format cmd string to inject into Python subprocess
    cmd = "mintapi '{}' '{}' --accounts".format(mint_user, mint_pass)
    
    # Store class method value in output variable
    output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    
    # Read output value and convert to bytestring
    jsonS = output.communicate()
    
    # Decode bytestring into JSON data Array object
    account_json = json.loads(jsonS[0].decode('utf-8'))
    
    for i in range(0, len(account_json)):
      if (account_json[i]['currentBalance'] != 0):
        print(account_json[i]['accountName'], end=' - ')
        print(account_json[i]['fiLoginDisplayName'])
        print('${:,.2f}'.format((account_json[i]['currentBalance'])))
        print('-----------------------')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search