Helping to Save money the Geek way using Python, @Trello and SQLite.

Last year I saw this article about the 365 Savings plan, where you save a bit of money each day for 365 days and over the year it amounts to nearly £700.  Christmas can be expensive so I thought why not give it go.  It works by on the first day you start you save £3.65, then the next day £3.64, then £3.63 etc, you get the idea.

Yes the first month is expensive but it's worth it.  Now last year I just set up a quick spreadsheet, put the date in one column, dragged it down to fill in the year and then 3.65 in another column and a formula A2-0.01 and dragged that down.

Key to the is to remember you have to do it each day ( I did forget a few days) and be disciplined to carry this out.

This year to help me remember a bit better, I wrote a quick script that every day will run, get the latest amount and create a card for me.

The way it works is, I created a very simple table called savings, just has one column and inserted into that 3.65 to start.  Then each day my little script selects the value from the table, creates the Trello card, then generates an update statement to set it to the next value. 

This is stored in an update script that gets updated for a variety of things throughout the day, sometimes I manually run the updates, if not I have an automated job that runs each night to ensure everything is up to date. 

Below is the statement to create the table and insert the first amount and also the Python code.  You will just have to change the location of your database file and input your Trello details, I have blanked out my Trello details, they are clearly marked.

SQL  

sqlite> create table savings (amount float);
sqlite> insert into savings values (3.65);

PYTHON

# Script Name		: savings_countdown.py
# Author			 	: Craig Richards
# Created				: 23rd October 2017
# Last Modified	:
# Version				: 1.0

# Modifications	:

# Description		: This will create a daily reminder to transfer my savings

import os
import sqlite3
import requests
from time import strftime

dropbox= os.getenv("dropbox")
scripts=os.getenv("scripts")
dbfile=("Databases/jarvis.db")
master_db=os.path.join(dropbox, dbfile)

key = 'YOUR TRELLO KEY'
token = 'YOUR TRELLO TOKEN'
cards_url = 'https://api.trello.com/1/cards'
params_key_and_token = {'key':key,'token':token}

conn = sqlite3.connect(master_db)
cursor = conn.cursor()
loc_stmt='SELECT amount from savings'
cursor.execute(loc_stmt)

while True:
	row=cursor.fetchone()
	if row == None:
		break
	print row[0],
	amount=row[0]

new_amount = amount - 0.01
f=open(scripts+'/batch_jarvis.sql','a')
f.write("update savings set amount = " + str(new_amount))
f.close()
name = ('Transfer ' + str(amount) + ' into Savings')
description = strftime("%Y-%m-%d %H:%M:%S")
id_list = 'BOARD ID'
arguments = {'name': name,'desc': description,'idList' : id_list}
response = requests.post(cards_url, params=params_key_and_token, data=arguments)

So it's nice and simple, automated and now I can't forget, please let me know what you think, email me or leave a comment below.

I am always interested in your thoughts so if you have any comments or feedback then please feel free to add any comments, or you can mail me  here.

Related Posts Plugin for WordPress, Blogger... 

 

Not good for HP

Clash Royale and the rise of gaming/esports