Tweet your MP

Ever wanted to send a tweet to your MP? not sure if your Member of Parliament has embraced social media? want to put a handy tool to do so on your website?

Tweet Your MP

Tweet your MP

Here’s a little script I wrote to find your MP using a postcode (via the TheyWorkForYou.com API) and send them a tweet. Info, source and background below.

It’s possible to tweak this tool to return email address, postal address, phone number and facebook page (if they have one) – you can also add custom information to each MP as well. My data set includes 436 twitter accounts for MPs – slightly more than Tweetminster’s 409 but I have included auto twitter accounts (so people can see you’re tweeting your MP, even if they don’t respond). I’ve tried to avoid spoof accounts.

Bit of background about this tool

This tool works by converting the postcode into a constituency name on TheyWorkForYou.com, and then matching this constituency name with MP’s details on a local MySQL database table. If you don’t want to use TheyWorkForYou.com’s API it is possible to buy a constituency postcode database from Ordinance Survey for £350.

For a while I’ve been working on an open-source activism tool. It was born out of curiosity, an excuse to learn a bit more about php and as a way of proving email to MP actions courtesy of the very useful theyworkforyou.com API.

Unfortunately it became on of these projects that got more and more complicated – once I’d got round to adding a graphical user front end, SMS texting, and add on modules it started getting a bit too big for me to handle. Plus I started encountering problems with PHP’s send mail function getting blocked by outlook servers, experimented a bit with pop mail senders and then started looking at using online cloud services.

The past 2 organisations I’ve worked for have used off the shelf tools instead, making the aim of the project a little bit redundant.

I still have a copy of all the code (with lots of comments) if anyone would like it – it’s in an alpha sort of works if you’re prepared to spend a bit of time tinkering with it state. Just drop me a line. All I ask is that if you do improve on it, please make it publicly available (it is GPL licensed).

I’ve also been thinking about the effectiveness of email-your-mp actions with identikit emails embedded in them – I think using twitter or even printed out letters might be a better way forward to creatively attract attention, and avoid the boring accusations of ‘slacktivism’.

So in the meantime I’ve taken the bits of the tool that did work, and have reworked them into a much simpler ‘Tweet your MP’ toolkit. The idea of this is to provide a simple widget you can embed on your website – I’ve seen plenty of websites that just link to TheyWorkForYou.com, or refer people to google, so this provides a way of keeping activists on your page.

In the example above I’ve just gone for twitter and website information – but with a few tweaks to the code you can add email your MP (via a mailto link) phone your MP or write a paper letter to your MP functionality.

Requirements & the code

To get this to work you will need access to a MySQL database and PHP. This is currently running on my server which is a cheap-as-chips 123-reg setup. Check your ISP’s documentation for support on how to get these logins. I’ve labelled the code to show what it does.

If there are any corrections please get in touch with me and i’ll add them.

Download the code from GitHub

I’m updating this to fix problems and add enhancements. At the moment the code does contain a bit of stuff left over from the webtivist project. The GitHub version will always be the most up to date.

To make this work you’ll need to upload the MP data spreadsheet to your MySQL server (I used the import function on my 123reg hosting and it worked fine) this has every MP’s contact details – if you’d like access to this please drop me a line as I’d like to keep track of who’s using it!

Then you’ll need to edit the settings.php file to include the login for your MySQL database, the hostname and tablename for your MP database.

You’ll also need to apply for a theyworkforyou.com API key – there’s usually no charge to use this for small volumes. They prefer it if you ask them if you’re intending to use it a lot. Please Please don’t use this to send identical emails to MPs.

For the twitter part you’ll also need a Twitter API key  I changed this to use the more simple @mention option on twitter.

Corrections / suggestions and contributions

Thanks to MPs being arrested for things, standing down or departing, this data may become out of date over time.  If there is incorrect information please let me know and I’ll update it.

This script makes use of the TheyWorkForYou.com API and Ruben Arakelyan’s php script. Check the comments in the code for more information.

Update: this script has now moved to tweetyourMP.com

, , , , , ,

2 Responses to Tweet your MP

  1. Richard February 18, 2013 at 9:43 pm #

    This is nice, Pete. Just as I always thought your open source activism tool was when we used to work together :-)

    Richard

Trackbacks/Pingbacks

  1. Tweet your MP goes dot com! - Kimondo - March 8, 2014

    […] Since I’ve upgraded my hosting, one thing I’ve been wanting to do was to find a proper home for my Tweet Your MP script. […]

Leave a Reply

%d bloggers like this: