Budget from the Command Line
Now that the SimpleFIN Bridge is up, you can check on your finances from the command line. Go sign up for the Alpha here!
First, generate a setup token. We’ll use the demo one (so you folks at home can copy and paste away):
SETUP_TOKEN="aHR0cHM6Ly9icmlkZ2Uuc2ltcGxlZmluLm9yZy9zaW1wbGVmaW4vY2xhaW0vZGVtbw=="
CLAIM_URL=$(echo SETUP_TOKEN | base64 -D)
echo ${CLAIM_URL}
Then we convert the setup token into an access url (this demo token can be converted any number of times, but real tokens can only be converted once):
ACCESS_URL=$(curl -X POST ${CLAIM_URL})
Save the access url:
echo "${ACCESS_URL}" > ~/.simplefin-access
chmod 0600 ~/.simplefin-access
We can get a JSON dump of our transactions using curl
:
curl $(cat ~/.simplefin-access)/accounts
which makes:
{"accounts": [{"transactions": [{"posted": 1465286400, "id": "demo-1465286400", "amount": "-8.88", "description": "Grocery Store"}, {"posted": 1465315200, "id": "demo-1465315200", "amount": "-22.80", "description": "Rent"}, ...snip...
Or we can get the last few days’ transactions:
$ python last_week.py
Mon --------------- --------
Movie Theater -11.60
Clothing Store -2.91
Rent -4.24
Clothing Store -7.29
Clothing Store -18.21
Good Person Rew -64.69
Good Person Rew 27.94
Grocery Store -3.55
-84.55
Tue --------------- --------
Grocery Store -8.88
Rent -9.12
Rent -8.01
Rent -22.80
Gas Station -0.25
Good Person Rew -52.25
Good Person Rew 19.02
Clothing Store -3.40
-85.69
Wed --------------- --------
Clothing Store -8.50
Movie Theater -9.49
Grocery Store -16.43
Movie Theater -23.74
Gas Station -11.84
Good Person Rew -52.00
Good Person Rew 39.40
Grocery Store -3.29
-85.89
Thu --------------- --------
Grocery Store -8.21
Gas Station -12.60
Grocery Store -4.71
Gas Station -31.50
Grocery Store -16.17
Good Person Rew -44.82
Good Person Rew 35.15
Clothing Store -5.41
-88.27
Fri --------------- --------
Clothing Store -13.52
Gas Station -0.50
Movie Theater -6.54
Gas Station -1.25
Clothing Store -18.88
Good Person Rew -70.02
Good Person Rew 29.85
-80.86
-----------------------
expenses -576.62
income 151.36
net -425.26
using this Python script:
#!/usr/bin/env python
from __future__ import print_function
import os
import requests
import time
from decimal import Decimal
from datetime import datetime
from collections import defaultdict
access_url = open(os.path.expanduser('~/.simplefin-access'), 'rb').read().strip()
scheme, rest = access_url.split('//', 1)
auth, rest = rest.split('@', 1)
url = scheme + '//' + rest + '/accounts'
auth = tuple(auth.split(':', 1))
day = 24 * 60 * 60
today = time.mktime(datetime.now().date().timetuple())
week_ago = int(today - 3 * day)
by_day = defaultdict(list)
params = {'start-date': week_ago}
response = requests.get(url, params=params, auth=auth)
data = response.json()
for account in data['accounts']:
for trans in account['transactions']:
trans['posted'] = datetime.fromtimestamp(trans['posted'])
by_day[trans['posted'].date()].append(trans)
pos_total = Decimal('0')
neg_total = Decimal('0')
for day in sorted(by_day)[1:]:
print('{0} --------------- --------'.format(day.strftime('%a')))
transactions = sorted(by_day[day], key=lambda x:x['posted'])
pos = Decimal('0')
neg = Decimal('0')
for trans in transactions:
amount = Decimal(trans['amount'])
this_neg = ''
this_pos = ''
if amount >= 0:
this_pos = amount
pos += amount
else:
this_neg = amount
neg += amount
print(' {memo:<15} {amount:>8}'.format(
memo=trans['description'][:15],
amount=amount,
))
pos_total += pos
neg_total += neg
print(' {empty:<15} {amount:>8}'.format(
empty='',
amount=neg+pos,
))
print('-'*23)
print(' {0:>15} {1:>8}'.format('expenses', neg_total))
print(' {0:>15} {1:>8}'.format('income', pos_total))
print(' {0:>15} {1:>8}'.format('net', neg_total + pos_total))
If you want to see your real transaction data on the command line, sign up to be an Alpha tester on the SimpleFIN Bridge. It costs $0.50/bank/month billed 3 months at a time.