Python Solves Group Financials

Python Solves Group Living Finances
Standard

Are you looking for a way to simplify your flat’s finances? Well I have the right script (i.e. small program) for you! To run this script you will need the following:

  • Programming Experience Required: None
  • Python 3 or higher installed on your machine
  • Access to your shared bank account via internet banking (don’t worry, this script won’t need your credentials, just the transaction data to sort out the mishaps!)

I’m currently studying towards a bachelor science in Computer Science and Psychology. Throughout my studies I have chosen to experience flatting i.e. living with a bunch of friends. This has always been a great experience, however there’s one topic that tends to be avoided to keep people happy:  money.

If you’ve had similar experiences in the past or are experiencing this right now then please keep reading, as this script can help you logically solve them. I would like to point out that I built this script for my own programming pleasure and it is very likely that you can get the same result a lot faster by using a tool you’re comfortable with.

This script is open-source and I promise it doesn’t send your valuable information /or finances across the internet. If you don’t trust it, ask someone with programming experience to take a look at it or don’t use. Better to be safe 🙂

This script requires a few things:

  • The .csv file which can be downloaded from your bank’s website
  • The Python script
  • Very basic command line ability (I will explain everything)
  • Python 3 to be installed

Regarding the command line, I’ll be attacking this from a Windows perspective, as I’m assuming anyone who has a distribution of Linux is well versed with the terminal. Just be careful with the direction of the slashes…

Download the .csv file and the .py script to a place you where you can find it. e.g. C:\Users\USERNAME\Documents\Python

It will also be helpful to rename the file to something smaller and that contains no spaces.
e.g. bankaccount_2014.csv

Now, using the file explorer, locate to where you’ve saved the .csv file and the .py file. It should look like this:explorer_cli_python_csv

Now we need to open up the Windows command line. Don’t worry, I like walk you through this and we will be using minimal commands. As a side note the command line can be very useful, so if this example feels fun, head over to your favourite search engine and do some research!

Now, hold down [SHIFT] on your keyboard, right click the folder and select ‘Open Command Window Here’

A window will open up with a very limited visual interface, but it’s very powerful once you know how to use it!

C:\Users\YourUsername\YourFolderPath is where you have opened the command line. To check that everything we want is there. Type dir /b and then press enter. What you should now see printed to the command line is all the files in the current directory, the /b is an argument given to display only the minimal presentation of files. If you’re interested try “dir” own it’s own and observe the difference.

Quickly we’ll check that you have Python 3 installed and accessible. Type python and press enter. If it displays Python 3.x.x, great! Press [CTRL] + [z] to end the Python interpreter. *If it displays “python is not recognized as a internal or external command, …” then you need to go install Python and add it to your path (The GUI installer has a drop-down entry for this)

Almost there! Below I will use XXX as a placeholder for the name of your .csv file. If that confuses you, rename the .csv file to XXX.csv (however, this might seem dodgy when you look back through your documents…)

To run the script on your data, type: python shared_bank.py XXX.csv 

If you’re rushing to look at the result, type: output.txt and press enter! This should open up the output of the script in your standard text editor (probably Notepad or Word, for most). Great, now go analyze those mischievous transactions and the fairness of everyone’s contributions. Stop here if you’ve had enough of the command line and just want to get to the number crunching!

Yay, you’ve made it. If you’re interested in attempting to understand the code, have a read over at GitHub,I originally made this script just for myself then I had friends complaining about similar problems, so I adapted it and sent it off to them. The “>” writes all the print calls to an output file. This should have been placed into the script, however I prefer to send the output through many programs in my spare-time. In the GNU/Linux terminal, this is referred to as ‘piping’ which uses the | key

I’ve now changed the script, so that it writes a file on it’s own.

It has been tested with Westpac and KiwiBank .csv files. I’m sure other banks format their data differently, as I couldn’t find a universal standard anywhere. Comment if the script doesn’t work on your particular .csv file and I’ll do my best to adapt it to your situation! You won’t need to give the .csv file, just one row (change the people’s names and figures at your will, it’s just the columns that are important)

Future Plans:

  • Optimize the code, so it runs more efficiently. E.g. use less nested for-loops, create a list for original name, upper and lower at the beginning instead of on the fly (i.e. pre-processing)
  • Add a Java GUI on-top of the Python code, so that the user can drag and drop their .csv file into the application without having to open up the command line
  • Format the output nicely (i.e. line-by-line) and possibly convert back to readable .csv
  • Create a ‘smarter’ version, that dynamically locates the name/date/input/total/description fields and can run without the user having to input the people’s names (dictionaries will be key here)

Hope it helps! Leave a comment below if you need assistance or would like to show your appreciation.
Farewell,
Carl