Project

lloydstsb

0.01
No commit activity in last 3 years
No release in over 3 years
A library for accessing data from Lloyds TSB's online banking
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 2.5.1
 Project Readme

Lloyds TSB screen scraper

I bank with Lloyds TSB - I have my current account and credit card with them. Like most online banking services though, they're not to up-to-date on APIs and the like. After looking around online, I found that there were a couple of scripts that people had built, but I didn't have much luck with them myself. So I decided to build my own screen scraper.

I know the code in this is pretty messy, and as ever, it's untested. I tried to refactor it and got to the end, but then it turned out to be broken and I couldn't be bothered to fix it. So I've left it for now.

Usage

The file example.rb provides a very simple example of how the code works, but here's a step by step:

  1. Ensure the gem is installed, and then include it in your Ruby file, or in your Gemfile where appropriate:
$ gem install lloydstsb
`require 'lloydstsb'
  1. Create a hash with three symbol keys, :username, :password and :memorable_word, each unsurprisingly corresponding to different authentication details used
@settings = {
  username: "123456789",
  password: "a secure password",
  memorable_word: "banking"
}
  1. Instantiate a new instance of the LloydsTSB::Customer object, passing in the hash from the previous step - this is used to perform the authentication required.

customer = LloydsTSB::Customer.new(@settings)

  1. Call the accounts method of the object you just made - it'll take a few seconds, and will return a number of LloydsTSB::Account objects. Play with the response as you wish.
puts customer.name
customer.accounts
customer.accounts.first.transactions

Data models

A LloydsTSB::Customer is created with LloydsTSB::Customer.new with a hash of settings passed in. It has the following attributes:

  • agent (Mechanize::Agent) - the Mechanize agent used to browse around the online banking system. This will be pointing at the "Your accounts" page.
  • name (string) - the name of the customer
  • accounts (array) - an array of LloydsTSB::Account objects representing accounts held by the customer

A LloydsTSB::Account instance has the following attributes:

  • name (string) - the name of the account
  • balance (integer) - the balance of the account, whether positive or negative. *(NB: The true meaning of balance is affected by whether the account is a :credit_card or a :bank_account)
  • limit (integer) - the credit limit for the account - this is an overdraft limit for a current account, or the spending limit on a credit card
  • transactions (array) - an array containing a number of LloydsTSB::Transaction object - this will be the 20(?) most recent transactions on the account
  • details (hash)__ - the identifying information for the account as a hash. For a bank account, this will have keys :account_number and :sort_code, with :card_number for credit cards
  • type (symbol) - the type of the account, either :credit_card or :bank_account

A LloydsTSB::Account has many LloydsTSB::Transaction instances in its transactions property. Each transaction has the following attributes:

  • date (Date) - the date of the transaction as shown on the statement
  • narrative (string) - a description of the transaction, most likely the name of the merchant
  • type (symbol) - the type of transaction, usually an acronym - a list is available on the Lloyds TSB site
  • direction (symbol) - either :credit or :debit, depending on what the transaction is
  • amount (integer) - The amount of the transaction, obviously...
  • unique_reference (string)_ - a hash to identify this transaction (fairly) uniquely...useful if you want to see whether a transaction is new or not

Limitations

  • I haven't tested this with savings account, so it may well mess the script up and cause exceptions. I'll need to open a savings account to test this.
  • It will only show a limited number of transactions - it doesn't navigate through the different pages

License

Use this for what you will, as long as it isn't evil. If you make any changes or cool improvements, please let me know at tim+lloydstsb@tim-rogers.co.uk.