Featured Hardware Projects Raspberry Pi

Monzo Bank “Pot” ePaper Tracker

||||| 0 Like |||||

Jason Barnett (from Cyantech) has written some excellent code to work with the new online-only bank "Monzo".

Monzo have a programming interface that allows you to query your bank account. They have savings "pots" where you can squirrel away money for a rainy day, or for your kids pocket money!

These interfaces (called API's) are secure and safe as you need to signup for an account and secure it with several different keys.

Follow Jason's code tutorial through first (https://boeeerb.co.uk/creating-a-monzo-pot-epaper-tracker/) and then pop back and check out my changes.

Well after following Jason's instructions – I decided that I wanted to add a little flair. As I have a license for Font Awesome Pro 5, I used the font on the display to get icons onto my display!

My altered code is shown below.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from PIL import ImageFont
from pymonzo import MonzoAPI
import simplejson as json
import inkyphat

font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 18)
font2 = ImageFont.truetype("/home/pi/fonts/fa-regular-400.ttf", 28)
font3 = ImageFont.truetype("/home/pi/fonts/fa-light-300.ttf", 28)

name = "Bank 'o Vince"
w, h = font.getsize(name)
x = (inkyphat.WIDTH / 2) - (w / 2)
y = 0
inkyphat.text((x, y), name, inkyphat.RED, font)

font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 24)
name = "Fluffy's Fun Fund"
w, h = font.getsize(name)
x = (inkyphat.WIDTH / 2) - (w / 2)
y = 28
inkyphat.text((x, y), name, inkyphat.BLACK, font)

font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 28)
monzo = MonzoAPI()
pots = monzo.pots()
out = json.loads(json.dumps(pots))
for item in out['pots']:
    if (item["name"] == "Rainy Day"):
        balance = (item["balance"]) / float(100)

pound = u'T'
gamepad = u''
heart = u''

balance = '{0:.2f}'.format(balance)

w, h = font.getsize(str(balance))
x = (inkyphat.WIDTH / 2) - (w / 2)
y = 60

inkyphat.text((10, 0), heart, inkyphat.RED, font3)
inkyphat.text((10 , y), pound, inkyphat.BLACK, font=font2)
inkyphat.text((x, y), str(balance), inkyphat.BLACK, font=font)
inkyphat.text((170 , y), gamepad, inkyphat.RED, font=font3)


The important changes are to allow Font Awesome Unicode to show.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

These two lines show I will run the code in Python 3 (not 2).
The second line shows I will be using unicode in the application.

pound = u'T'
gamepad = u''
heart = u''

These are the glyphs I am using for the display. To find the right glyph was a little tricky, but if you do the following it will save you a lot of time

  • Go to https://fontawesome.com/get-started and download the zip file (Free or if you have paid for pro – the pro file)
  • Unzip the files and look for the folder "on-server" and then one called "webfonts"
  • In that folder look for the files that end in TTF (File type TrueTypeFont)
  • Copy one or all of these onto your Raspberry Pi
  • Go to https://fontawesome.com/cheatsheet and find an icon you would like to use
  • Copy the icon image (may take a few attempts, paste into Notepadd++ or simular to ensure you only have the glyph)
  • Paste the resulting "text" into the code after the u between the ' marks
font2 = ImageFont.truetype("/home/pi/fonts/fa-regular-400.ttf", 28)
font3 = ImageFont.truetype("/home/pi/fonts/fa-light-300.ttf", 28)

Finally change the path in the two lines shown above in your code to show where you copied the files on your Raspberry Pi.

Run the code and wait – you should see some cool icons appear. If you do not, check your font path, check the glyph you have copied and finally message me on twitter for some help!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.