Okay, so day one of that site is over, with some lessons learned and some serious improvements made!
About 11AM, just as I was trundling along the M25 on my way to Egham, TheyWorkForYou made a change to their API method, getMP, which PoliticsPosters uses to find your MP from your postcode (or at least did- more on that in a tick). Basically since our MPs aren’t technically our MPs, the method started to return nothing, a case I hadn’t considered. Fortunately they provided the always_return option, so when I got back from a successful day in Egham at around 7PM, I quickly fixed that.
Next bug: In any election, constituency boundaries are likely to change. In this one, we got plenty. My lookup had previously been this:
-
mp = PoliticsPosters::API.twfy.mp(:postcode=>params[:postcode], :always_return=>true)
Trouble is, this doesn’t work if your boundary has changed (and thus your last MP has changed). To do that, we need to use the getConstituency call with the new ‘future’ flag.
-
constituency = PoliticsPosters::API.twfy.constituency(:postcode=>params[:postcode], :future=>1)
-
mp = PoliticsPosters::API.twfy.mp(:constituency=>constituency.name, :always_return=>true)
And now we’re good! Easily fixed, overall, and it removed the two biggest problems. The other problems are a little trickier. One remains- handling of special characters in MP names. There’s a few MPs with circumflexes and the like in their name, which is fine if you have a language/framework/tools that support UTF8 encoding (which Ruby/Sinatra/Prawn does). But the font I’d chosen, Chunk, didn’t have any of the characters it needed to render. This remains an issue, and my current planned work-around is to degrade to another font for pages and posters that handle those names. I’ll sort that out tomorrow, though- this post is, after all, being put together at 3AM, and I have to sleep sometime.
The only other thing people wanted was more posters. I have been happy to oblige. I combined the PublicWhip policy feed provided through TheyWorkForYou, wrote a tiny scraper to get the titles off the PublicWhip site (since there’s no API for that I’m aware of), stuffed it together in PostgreSQL through DataMapper, and now I can do something like this:
-
PoliticsPosters::MP.first(:full_name=>'David Cameron').policies #=> [<#PoliticsPosters::MPPolicy policy_id=4 distance=0.05 etc>]
Which is very, very neat, and means that developing stuff is very easy. I dug around in the source code for TheyWorkForYou and pulled out their code for rendering PublicWhip data to get the same policy IDs and descriptions, wrote some methods to scale color and size, and stuffed it all together to produce the new and updated constituency page as well as new posters- one for all policies, and one for each individual policy. The individual policy posters are rendered on demand, whereas the common constituency ones are rendered on the first view of a constituency page.
The Linode VPS has been handling the load without even noticing. Despite the site being inoperative most of the day, it got 10,000 hits from nearly 4,000 unique users, who downloaded nearly 2,000 posters. Not bad for a first day.
Tomorrow I hope to sort out UTF8 character handling and maybe even get around to publishing the source code to the site if I have a spare moment.
Hi James,
Fantastic idea for the posters – unfortunately they don’t work for the Romsey postcodes around SO51 7UN/7UP etc. I have checked with my old postcode in Southampton and it works perfectly, but the Romsey boundary has changed since the 2005 election (added Southampton North) and these houses were probably built around that time as well!
Our current MP is Sandra Gidley, Lib Dem, but I’m not sure how much that helps!
Cheers for all your work anyway!
Melody
I’m having a problem with getting a poster for the “North Southwark & Bermondsey” constituency (former MP Simon Hughes). Postcodes such as SE1 1AA and SE11 1SZ don’t work, but they do work when doing a search on theyworkforyou.com. Maybe the problem is that Simon Hughes was one of the brave few who actually did turn up and vote against the Digital Economy Bill?
@Melody: I’ve changed some code to better handle boundary changes so it’ll now ask which constituency you want to see info for- your old or new one.
@John: Works for me! http://politicsposters.co.uk/North-Southwark-Bermondsey Probably related to to the above problem; there were some issues doing postcode lookups for a while on boundary changes.