Further to my post on installing Ledger I’ve been writing my own script to logon to my bank and download transactions. Pocketsmith does this via Yodlee, but before Pocketsmith introduced Yodlee integration I’d written a couple of things previously for processing Smile web pages to the Qif format so I could upload to Pocketsmith; however, these aren’t going to work for me from the command line so I wrote this script instead.
It is still work in progress, but to be honest it is already in a good enough state for me so I wouldn’t expect I’ll be making many more improvements to it (although you never know).
There is nothing really exciting about the code at all so rather than pick and show snippets of the code directly I’ll talk about a couple of approaches I’ve made that I’m unsure about.
Instance variables vs arguments
This is very likely coupled to the below and both of these are probably due to me trying to do things in what I perceive as the Ruby way when really I should have just kept it as one long hacky script.
Using instance variables seems necessary to keep state between all the methods (I.e the current page that is being web-scraped), but isn’t using instance variables in this way just as bad as using global variables? Should each method handle the current page as an argument instead? I’m not sure, this approach might actually be more messy than using instance variables. If I get exceptionally bored I might try a few different options.
Splitting things into methods when those methods make no sense on their own.
I like the idea of splitting up the separate stages of logon into different methods and being able to cleanly list one after the other to call them, instead of having one long script, but does it actually make sense to do this? I’m not sure. To me it seems odd to have a method that literally cannot be used unless a number of other methods have been run before it in the correct order. Perhaps it would make sense in a rakefile as separate tasks with dependencies? Perhaps I should just make each method call the method before it and cascade the dependencies that way? Perhaps I’ll try…
[EDIT] I went ahead and tried an alternative approach before I even published this post, it’s in the
cascade_methods branch. I’m undecided if it’s better or not though.
[EDIT:2015-07-27] I ended up merging in the
cascade_methods idea. I decided I liked it better. I’ve also used highline for obscuring input of sensitive data.