Tool to get your Opal card travel data
The New South Wales public transport system uses the Opal smartcard as its payment mechanism. This means their servers store every trip that you make, including the start/end times and locations.
They need this data for billing, so there’s not much we can do about it from a privacy point of view. However you may be interested in getting your own copy of your data for making pretty graphs or other analyses.
Introducing…
Enter opal-card-tool.
Requirements:
- python3
- python-lxml
- python-requests
- gnuplot (optional for graph support)
- An account on www.opal.com.au
Example usage
$ opal-card-tool --help usage: opal-card-tool [-h] [--num-days NUM_DAYS] [--card-number CARD_NUMBER] (--load | --show-cards | --show-transactions | --graph-commuter) Opal card activity fetcher optional arguments: -h, --help show this help message and exit --num-days NUM_DAYS restrict to NUM_DAYS of output --card-number CARD_NUMBER Opal card number or index (eg: 0,1,etc --load load any new data from the Opal website --show-cards show a list of cards --show-transactions show transactions for card --graph-commuter draw commuter graph for card with gnuplot $ opal-card-tool --load Username: example Password: example Loading transactions for 1234567890123456 . done $ opal-card-tool --show-transactions|head -n2 number,timestamp,amount,details,fare,fare_applied,fare_discount,journey_number,mode 1234,2016-01-01 09:00:00,-$4.50,Some St to Some Other St,$4.50,,$0.00,0,bus
Other interesting things
Each time you run opal-card-tool --load it fetches any new transactions from Opal and adds them to ~/.cache/opal-card-tool/pickle. Your username and password are also saved here, so keep that file safe! The tool does not connect to the internet unless you ask it to load additional data with this flag.
You can easily get a CSV of your card data for easy analysis with a spreadsheet or other software:
opal-card-tool --card-number XX --show-transactions > transactions.csv
There’s also the --graph-commuter option. I use this to see how long I spend at work.
Hi, Need some help with the tool
Sadly this doesn’t work any more
@Gordon, fixed!
I cannot run this python, when i run ($python opal.py –load)
it hangs after entering username and hitting enter, never asks for password. am i missing something
Hi @Jarrod,
I’m using the standard Python getpass.
If you’re running on Windows it’s possible that the prompt is just not being printed. In that case try typing your password and pressing enter. It may just work :)
Can someone please make a video guide of how to use this. I need it to submit evidence to contest a false penalty notice (fine) that I received. The recommendation is to supply 3 years worth of opal travel to prove I have not evaded fare costs before. Please.
Really nice work – thanks