This past weekend I took a trip down to London for Rewired State’s second UK Parliament Hackday. Part of Parliament Week, it was an open hack using a whole variety of data derived from Parliament and House of Lords activity.
I ended up missing out on the actual Parliament tour for administrivial reasons, but that did at least allow for a leisurely breakfast at one of Shoreditch’s less achingly-trendy coffee joints. The caffiene, as it turned out, was needed.
The weekend kicked off withe a tour through the available data. A of it lot was the kind of stuff that I was already familiar with through Hansard and TheyWorkForYou, but I was immediately caught by the data from the annunciators. These are screens dotted around the Parlimentary estate that display information about what’s going on - what kind of business is being transacted, who’s speaking, what the subject is about and so on. They also control the division bells, which are sounded whenever there’s a vote to be taken.
The idea is that any MP or Lord who hears the bell then hightails it to the division lobby, stopping only to leave their brains behind. Once there, they then file obediently through the ‘Aye’ or ‘No’ lobbies according to how the party whips tell them to think. OK, I’m going to try and not be cynical for the rest of this post. The division bell is a real, actual, ringing bell, and can be heard (apparently) anywhere on the Parliamentary estate.
Hilariously, there are also bells in several of the local hostelries around the Westminster area - draw your own conclusions, but votes tend to take place late at night.
This immediately struck me - as well as Sam, Shaun and Alistair, - as a 19th century process which was ripe for improvement. So we set to, me building an iOS app, and they variously hacking with Python and Rails and Twilio. The end result is Bernard, a service that takes the information displayed on the annunciators and broadcasts it via push notifications to iOS clients, SMS broadcasts, a web front end and text-to-speech calls.
Challenge number one was the source data. The annunciator system is entirely proprietary, very old and was conceived in a time before networks, never mind the internet. The nice Parly people gave us a dump of the data for 4 hours in the Lords last Thursday, and we went from there.
It turned out to not have been a particularly busy day in the Lords, which in some ways was probably a good thing due to the quite frankly baroque syntax of the data. With a lot of Python parsing and some educated guesses, we ended up with a JSON feed of activity, people and process data, together with division bell alerts.
The iOS app uses push notifications over Apple’s cloud infrastructure. Getting this up and running was actually suprisingly easy thanks to some step-by-step guides on generating the certificate pairs needed to authenticate the push server with the Apple cloud. Getting an app to subscribe to pushes is one line of code, and reacting to notifications doesn’t take much more.
Considering the engineering challenges of the entire infrastructure, the client end is remarkably hassle-free to build. Push notifications are limited to a tiny 256 byte JSON payload, so there’s not a lot of information can be supplied on one. In the end, I implemented it by stuffing the alert type into the notification and using that to trigger a call back to Bernard’s API. That publishes the data as a JSON feed, so the apps then consumes the JSON data and displays the results.
Towards the end of the day on Sunday things got a bit more sophisticated, as I plugged in a TheyWorkForYou parser that I’d written previously so that additional information about the speaker could be downloaded and displayed.
Division bell notifications work slightly differently - they pop up an alert using the native Notification Center functions if the Bernard app isn’t running; or a custom view inside the app if it is.
All this was hacked together between midday on Saturday and 3pm on Sunday, with a few hours inbetween for sleep. Graceful, elegant code it is not - but the data parsing pieces are completely backed by unit tests, as building them test-first is actually far quicker than the debuggy alternative.
Demoing at the show and tell didn’t quite work either, as the iPhone refused to talk to the projector. The fallback point-a-video-camera-at-the-screen approach must have worked well enough, though, because the judges gave us the What’s Happening Now category award. I’ve now got a bottle of Speaker Bercow’s Single Malt Scotch Whiskey to enjoy for our efforts. Details of Bernard are here, the main code is here, and the iOS app is here.
Why Bernard? Because we were asked for a name for the project after not enough sleep, and put on the spot we came up with Bernard after Bernard Woolley, Principal Private Secretary to the Rt Hon Jim Hacker MP. It’s a cultural reference for the over-40s, at least.