I want the weather forecast waiting for me on my little Raspberry Pi-powered internet printer in the morning. I tried signing up for the Printer Weather forecast app but it never worked – maybe it’s not running at the moment. I couldn’t work out how to install it myself, so I was a bit stuck.
Then I had an idea. I use IFTTT to email myself a weather forecast every morning. IFTTT stands for If This, Then That (or is it ‘If That, Then This’?). It glues together different web sites and services like Gmail, Flickr and Twitter in ways that can be incredibly useful. I had an idea to use the weather service on IFTTT combined with JD Harper’s really neat idea for using Dropbox text files as a way of printing to a GoFreeRange printer.
His insanely clever idea is to use a Python script to poll a Dropbox folder for text files – as new ones appear, his script reformats them as HTML, sends them off to the GFR backend print server with your printer’s URL, so the text prints. It then moves the text files to another folder so they don’t get printed twice.
Like JDHarper, I have a Mac, but I had a few issues getting his Python script to work. I had to install ‘elementtree’ and update the Mac’s version of Python from 2.4.4 to 2.7.7 as getcode() wasn’t supported in Python 2.4.4
I then used crontab to get the Mac to run the Python script every minute. (There’s another really useful guide to scheduling tasks with cron in MacOS X here.) My crontab.txt file looked a bit like this:
* * * * * cd /Users/gilesbooth/RaspPi/printer/ ; python printtxt.py
The first bit changes the directory the folder where JD Harper’s Python code lives, and the second bit runs it.
I loaded it by typing
at the command line.
It worked! I could now drop a text file, anywhere in the world, into one of my Dropbox folders, and (as long as my Mac is turned on) it prints on my little printer, wherever the printer may be.
This is where IFTTT comes in, and things get really tasty. Instead of getting the weather emailed to me, I changed my IFTTT recipe to send it as a text file at 6am each day straight into the Dropbox folder which is polled by the Python script on the iMac. I added a bit of HTML to the forecast to make it easier to read, but it works!
Obviously, having to have my iMac turned on sucks rather. So the next thing to do is to get the RaspberryPi to do the work of the iMac, if it’s possible to get the Pi to poll Dropbox folders… and some pictures would be nice. I might also re-write the Python script to make the formatting prettier.
I have now managed to get it all running on a Raspberry Pi, with no need to have an Mac running to get files from DropBox to the GFR print server. Details to follow in a new post here.