Pezholio

Make Your Own Food Safety Twitter Bot With Scraperwiki and Ifttt

| Comments

Food safety is a subject very close to my heart, and something I can get very geeky and passionate about.

This isn’t because I’ve ever been struck down by a particularly nasty case of the runs, but because I’ve been very heavily involved in the publication of online food safety inspections reports since 2006, when I worked on Ratemyplace, the food safety inspection website for Staffordshire councils.

Because of my work with Ratemyplace, I’ve had a lot of people asking “can we get Ratemyplace in my council area?” It’s not really up to me, but I have put something together that will replicate one aspect of Ratemyplace’s functionality - Twitter alerts, for your council area without you having to write one line of code.

Step 1 - Get the data

The first thing you’ll need to do is look on the national Food Ratings website, to see if your council is there. More are being added as time goes on, so if your council isn’t there, there’s a chance they’ll come on board in the near future. The best way to do this is have a look on the open data page and scan down the list (it’s divided into regions, which makes it easier).

If your council is there, click on the link marked ‘English language’ (which is the link to the data), and copy the address from the address bar. Armed with this link, you’re then ready for the next step.

Step 2 - Make your scraper

I know what you’re saying, ‘but you said this wouldn’t involve coding!’ Worry not, dear reader, this won’t hurt a bit.

Next, you’ll need to create an account on ScraperWiki. Once, you’ve done that, go to this scraper on ScraperWiki, and click ‘Copy’ as highlighted below:

Copying the scraper

You’ll then be presented with the inner workings of the scraper, but don’t worry, all you need to do is replace the text that says {ENTER YOUR URL HERE} with the url you copied earlier. Once that’s done, you can rename the scraper to something more meaningful by clicking on the title (as shown), and then click ‘Save Scraper’ at the bottom right of the screen.

Editing and saving the scraper

Once your scraper is saved, you can click ‘Back to scraper overview at the top right of the page’ to see your scraper’s page. Now click edit, under the ‘Schedule’ section as highlighted below, and choose the ‘Run every day’ option.

Setting the schedule

Then click the ‘Run now’ button just above the ‘Schedule’ section, and go an make a cup of tea. Depending on how busy Scraperwiki is, this should take around half an hour.

Step 3 - Making your feed

Once you’ve had a cup of tea, refresh the webpage with your scraper in, and it should look something like this:

A working scraper

This means the scraper has done its magic and you can now more on to the next step. Click the ‘Explore with API’ button as marked below:

Explorer with API link

Now, copy this code below:

select name || ", " || address as title, "Rating: " || rating  as description, link as link, lng || " " || lat as "georss:point", date from swdata  order by date desc limit 10

and paste it into the box marked ‘query in SQL’, then click ‘copy’ as shown below:

Making your feed

Paste it into a text editor and add format=rss2 to the end of the URL. You now have an RSS feed, ready to take along to Ifttt

Step 4 - Tweet your feed!

Next, pop along to Ifttt and create an account. You’ll also need a Twitter account, either your own, or a specific Twitter account for this purpose (I recommend the latter).

In true Blue Peter style, I’ve prepared a ‘recipe’ for you to follow on Ifttt. Once you’re logged in to Ifttt, go to the recipe, click ‘Activate’ under the Twitter Channel heading to connect your Twitter account (make sure you’re logged in to the right account!), follow the instructions on the window that pops up, then click ‘Done’.

Next, scroll down and in the box marked ‘Feed URL’, and copy and paste the URL you created earlier.

Ifttt

The next box shows the format that the Tweet will be posted in, you can fiddle with this if you want, or just leave it as is.

That’s it! Just click ‘Use Recipe’ and every time the ScraperWiki scraper picks up a new inspection, your Twitter account will tweet it!

If you want to see it in action, check out @EatSafeWalsall. I’ve been running this for a while, and it seems to be picking up quite a few followers!

If you do use this recipe, or have any problems following my none-too-lucid instructions, please let me know in the comments. Have fun! :)

Comments