Following the initial joy and elation at discovering we’ve got yet another chance to express our electoral opinions I’ve updated TweetYourMP.com to now include candidate information for the forthcoming 2017 snap General Election, and I’ve even managed to secure yet another dot com – TweetYourCandidate.com includes the details of over 3,000 candidates standing in the 650 constituencies across the UK.
Fortunately this time around I’ve been able to make use of the very useful candidate data from The Democracy Club which has saved a lot of time and made it possible to turn update the site in a very short space of time.
This time around there’s a new feature to play with: the campaign generator makes it possible to create your own pre-filled twitter campaigns to share.
As an example I created a very simple campaign – posing possibly the easiest question to people vying to be your Member of Parliament:
Sadly I’ve yet to receive replies from Kate Hoey (The former Labour MP) nor Dolly Theis who is the Conservative and Unionist Party candidate, although in the case of the latter I did tweet later as my initial candidate list didn’t include her twitter details. UKIP are not running in Vauxhall.
So far a number of campaigns have made use of the tool – which is provided free of charge, as a spare time project.
Rather excitingly my little side project tweetyourmp.com was mentioned by pukka chef Jamie Oliver as part of his campaign for healthy eating:
Big yellow sign
After my panic that I might not have enough bandwidth subsided, I thought it might be a good moment to give Tweety our MP a bit of love, so I’ve added the option to pre-fill tweets.
The tweet text is passed across using a custom URL – this can be done as follows:
Pre-filling in the postcode and tweet message:
Make sure you use the URL http://tweetyourmp.com/index.php
Passing values to tweetyourmp.com in this way works with spaces, but safer to encode the message and postcode parts using http://andrewu.co.uk/tools/uriencoder/ to replace characters with %20 for a space.
hello @ChukaUmunna your twitter message via @kimondo
as the tweet.
Important note on using hashtags
I had to use a bit of a hack to make it possible to have a pre-filled tweet with a hashtag. As # is used to denote an anchor link when you stick it in a URL the rest of the URL gets ignored by the bit of the code that reads the tweet from it.
To get round this use an asterisk * in place of a hash # – the code then puts the hash back in when it sends the tweet:
hello @ChukaUmunna your twitter message #hashtag via @kimondo
The salutation is fixed as ‘Hello’ but can be changed – is important not to begin the tweet with the @handle as it reduces its visibility and ‘Hi’ is a bit American sounding hence the hello.
Next on the list is building some sort of Raspberry Pi based tweet totaliser. You can download the (very simple) code that runs Tweet your MP on GitHub – a couple of interesting options are to use the code in a thankyou email after a supporter has completed an action to give it a bit more impact, or to sort through your data and merge in constituency contacts in an email.
Note that some MPs don’t consider twitter an ‘official’ communication format so this is best combined with an email or letter to an MP.
tweetyourmp.com is made possible thanks to the theyworkforyou.com API – this is free for charitable use up to 50,000 queries.
Update: I’ve now added a page that automates this process and builds a bit.ly link with the correct address!
Here’s a quick guide to running the ghost blog platform on a $25 Raspberry Pi.
Here’s my test blog
Ghost is a new piece of blog software, currently under development which was recently funded by a Kickstarter campaign. Ghost is a completely new blog platform which aims to concentrate on writing and has a really nice minimal, instantly updating theme.
Ghost uses node.js (a new one on me) and can run on the Raspberry Pi computer. So I thought I’d put together a few instructions based on my trial and error. You need to be a Kickstarter backer to download the code, although this will be released fairly soon.
This assumes you’re running the latest raspbian build.
sudo tar xvzf ~/node-v0.10.5-linux-arm-pi.tar.gz --strip=1
cd node-v0.10.5-linux-arm-pi
node –v
(this should display the version number to test things are working ok)
then install ghost:
mkdir ghost cd ghost
For the next step download and install ghost-0.3.0 from the ghost website – at the moment you need to be a kickstarter backer – log into the Ghost website, and download ghost-0.3.0.zip onto your Pi.
The built in browsers on the pi are a bit slow for blogging (particularly if you’re accessing it via a VNC connection) so to speed things up you can access your Ghost blog over your local network:
In the /ghost directory edit the config.js file. You’ll need to know your Pi’s ip address – you can get this from running ifconfig – ideally you need to set up your Pi to have a static ip address –
sudo nano config.js
replace “host: ‘127.0.0.1’” with “host: ‘<your IP address>'” and “port: ‘2368’” to “port: ’80′”.
and then enter your Pi’s ip address onto another computer on your network – you should now see your Ghost blog!
If found it very occasionally slows down when setting up users, but once I started adding posts and images it worked really smoothly on the Pi. Having a window open with an SSH session is interesting to see the software updating as you edit and create posts on the blog.
First impressions? it’s very minimal, but the lack of distractions makes this feel like a very creative blog platform to use – it’s not going to compete with the likes of wordpress and drupal for building fully fledged CMS websites, but as an alternative to tumblr or blogger it has a lot of potential.
Here’s the side by side view
Ghost’s approach will be to offer the software as a free download for self hosting, or paid accounts via the website (like wordpress).
I’m looking forward to see how this evolves in time, hats off to the Ghost team.
Update: making your local blog available on the internet:
I’ve been making my ghost test blog available on the internet – this is handy if you want to be able to update your blog from anywhere – although I wouldn’t recommend it for a production website that might get a lot of traffic, as it’s entirely dependent on your home broadband.
This is assuming you have a residential broadband account (I’m using BT broadband). Most home accounts used dynamic IP addresses, assigned by your service provider that change each time you connect to the internet – we’re going to use a service called no-ip.com which uses a program on your Pi to find out it’s address, and update a domain to point to this address. We’ll also need to open a port in the home router to allow connections to the Pi.
First sign up for an account at noip.com – there is a free option available, or you can opt to pay $15 a year for a service with more features.
Add a host, and choose a hostname from the list of options.
Next choose the DNS-A host option and save. The settings I’ve been using are below.
Next, on the Pi download and install the noip software (here are the instructions from RaspberryPihelp.net – check out their page if you want no-ip to run each time you switch on your Pi)
Whilst installing it will prompt you for your noip.com login details.
Finally you need to open a port in your router to allow traffic through – there is a port forwarding guide for most routers available here – I found that logging in to my router by visiting http://192.168.1.1 in my browser, finding the advanced menu and adding the local fixed IP address of my pi and web forwarding worked for me.
Hopefully if everything is working you should be able to see your Ghost blog in the wide world: my address is
Here’s another super simple widget, for creating links that generate tweets when you click on them.
advanced tweet technology
I use these links a lot in marketing type emails for work and tend to use quick and easy online tools (because I’m lazy), but I’m always slightly nervous about sending links via another website, that might get shutdown or move.
This makes use of the bit.ly API so you can track the number of clicks on your link, and then compare that to the number of tweets sent – check it out below:
You can download the source on github – feel free to hack about with it. It’s just 3 files (including the CSS). You just need a website that supports PHP which most do, and a bit.ly account.
Edit the settings at the top of the bitlytotweet.php file to include your source (this can be anything), username and API key. As this script makes use of your own bit.ly account you might want to hide the widget page and not make it public.
If you’ve lamented the loss of twitter’s v1 API which was switched off in June 2013 – and the ability to generate RSS feeds of your tweets and mentions here’s a handy tool for getting them back.
twitter + tools
Twools is a set of twitter – tools (geddit?) to generate feeds that uses twitter’s API version 1.1 – you’ll need to apply for an API key to make it work, and you’ll also need a server to host the software. I’m running twools on my cheap-as-chips 123-reg hosting package, so if you’ve got web space that’s capable of hosting a wordpress blog you should be ok. Installation is a matter of uploading to your webspace and following the enclosed instructions on modifing the settings file.
One note – this is a beta tool, so it’s provided as-is – it does include password protection, but I’d suggest using a different login to your normal one, and not making the front-page public. The feeds are public but fairly easy to hide.
RSS feeds are quite useful (despite what twitter thinks) – it’s possible to use them for things like a twitter badge on your website, or if you’re feeling a bit more creative setting up triggers on If This Then That (IFTTT.com).
Twitter triggers disappeared from IFTTT last year – but the very handy Twools can help you get them back.
For instance – you want to get an email when someone mentions your website on twitter – or perhaps you don’t want to miss a tweet from your mother in law. Or perhaps you want to drive some hardware with a tweet – like the Raspberry Pi ledborg I had a go with recently.
Using the feeds generated by twools you can generate notifications really easily whenever a new item is added to the feed – here’s an example on IFTTT.com. There is a limit built into the API but i’ve not hit this yet.
All in all it’s very useful – you can download Twools by subscribing to the newsletter on http://iag.me/twools/ – the author Ian Anderson Gray also responds to tweets.
Update: Twools is now available as a wordpress plugin! (taking care of the login security)
Sometimes it’s handy to be able to get people to tweet from a selection of messages – for instance on a thank you page after taking an action. Usually everyone just hits the tweet button and sends multiple versions of the same message out on twitter.
One thing that was interesting about the (I hate to mention it but..) Kony 2012 campaign was the splattergun approach to sharing multiple messages on twitter.
To make things a little bit more varied you can use this super-simple tweet rotator script – this picks a tweet at random from a list you provide in the javascript. It’s fairly easy just to come up with 10 or so different variations on your tweet and include them in the script – see the example below.
It’s also something that might work quite well with advocacy targets – anyone using tweetdeck to monitor their @mentions will see a varied response – particularly when you factor in that a few of your activists will change the tweet before they send it.
Foldable.me is a kickstarter funded, make your own Mii style character app. For $11 you get a nicely printed push out cardboard model of yourself. Although my hair isn’t exactly that colour, I do have that jumper.
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
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.
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.
Here’s a little project to build a very simple web-controlled multicoloured LED indicator with your Raspberry Pi and the PiBorg LEDBorg board.
Using IFThis Then That (IFTTT.com) – a simple online service which allows you to daisy chain different web things together – you can light up your Pi’s LEDborg based on particular events.
Take for instance it’s predicted to be frosty outside – your Pi could light up blue, or perhaps someone’s just mentioned you on twitter – your Pi could light up green. Or your boss has just emailed you and your Pi lights up red. IFTTT allows you to set up alerts based on a wide range of events. You could even potentially use your Pi to trigger events by sending information to IFTTT – but in this example I’m just using it as a receiver.
Spidey checking out the LEDborg
At about a fiver, the LEDBorg is one of the cheapest add-ons available for the Pi that plugs directly into the GPIO (General Purpose Input and Output) pins. It consists of a single 3 colour LED surface mounted on a board with a controller chip. It’s fairly simple – if you’re feeling adventurous you could probably have a go at building your own version, although it would be tricky to make something so compact. The LEDBorg fits neatly over the GPIO pins and would probably fit inside most Pi cases – I’ve opted to use my upright lego case to show off the light better.
First you need to fit your LEDborg, and install the software according to which revision of the Pi you have.
The LEDborg comes with a nice app that runs in a window – you can use this to test that everything is working correctly. My first impression of the LEDborg was how bright it was – it’s considerably brighter than the on-board indicator lights:
Resistance is futile
Next comes to automating the LEDborg to work with our online service IFTTT.
To do this I’m going to be using a specially created email account. There are other ways to do this which are a bit quicker, but email is easy, doesn’t require much setup and as long as the Pi has internet access it will work. In this example I’ve opted for gmail.
Next we need a bit of code on the Pi to check the gmail account, and fetch the subject of the latest email sent to it. This code then uses the email subject to program the LEDborg. This is my first attempt at writing Python (so be kind if you spot any mistakes!) – you just need to change the your_email_address and your_password for the bits you set up:
import imaplib
import email
#connect to gmail
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('[email protected]','your_password')
mail.select('inbox')
mail.list()
typ, data = mail.search(None, 'ALL')
for num in data[0].split():
typ, data = mail.fetch(num, '(RFC822)')
typ, data = mail.search(None, 'All')
ids = data[0]
id_list = ids.split()
# get most recent email id
latest_email_id = int( id_list[-1] )
for i in range( latest_email_id, latest_email_id-1, -1):
typ, data = mail.fetch( i, '(RFC822)')
for response_part in data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1])
varSubject = msg['subject']
varFrom = msg['from']
varFrom = varFrom.replace('<','')
varFrom = varFrom.replace('>','')
if len( varSubject ) >35:
varSubject = varSubject[0:32] ='...'
#print the subject to test
print varSubject
#output the subject to the ledborg
LedBorg = open('/dev/ledborg', 'w')
LedBorg.write(varsubject)
del LedBorg
You can test this by sending an email with the subject line 111 to the gmail account and by then running the script with:
sudo python ledchecker.py
Hopefully your Pi should be bathed in white light!
The position of the number in the subject refers to the red green blue LEDs in the LEDborg, and the value the intensity 2= full 1=half 0=off
So 100 is dim red, 200 is bright red. You can mix colours by using different combinations. Sending an email with the subject 000 switches the LEDborg off.
Excellent – but we don’t want to be constantly typing in the commands to run the script all the time – to get by this we’re going to use cron (think of it as Linux’s cronometer – a regular clock that does things at regular intervals). For a bit more info about cron check out this blog from David Singleton.
We can set cron to run our ledchecker.py program every minute:
sudo crontab -e
Opens your cron table in the nano editor – you just need to add
* * * * * sudo python /home/ledchecker.py
and then control-O to save and control-X to exit. You might need to adjust the line above depending on where you saved your python script.
Now your Raspberry Pi should automatically check the email account every minute and light up the LEDborg if it receives the appropriate email.
The final step is to head over to IFTTT.com and try creating a ‘recipe’ to feed your Raspberry Pi with information – I’ve created a simple recipe to get you started. If you think of any good ones, please share in the comments below!
Next thoughts are how to improve on this – perhaps it could cycle through last 5 emails? blink if it’s something really important? have a wired up ‘reset’ button. Play a chime when the notification changes?
Update: Fork me!
Brilliant – vwilcox has forked the original script and made it better – it’s now indented properly, and has a loop to check if there’s no email, for rejecting the email if the subject is too long, and a nice empty the inbox function. This is the first time anything I’ve written on gist has been forked, so that has made my day (in a very nerdy way) – thank you!