Using Huginn
My recent tinkering with Slipstream and micro.blog has been going quite well. The convenience of automatically piping my social media activity elsewhere to Tumblr has certainly resulted in more frequent posting there, which was my main goal. While IFTTT is easy to use, it has its limitations, but I didn’t know of any alternatives. That was until I accidentally came across Huginn.
I’m not even sure how I found it now. I was investigating Docker as a way of doing local development without littering my computer with piles of conflicting packages. There’s a Docker image for Huginn, which might have been where I came across it, but in any event, Docker made it extremely easy for me to try out Huginn (and its many Ruby dependencies) without messing up my system for evermore. I’ll have to write about Docker at some point, because it is a mind-bending but extremely handy thing to know about. Anyway, I could immediately see that Huginn would probably be able to replace IFTTT for me. Basically, it’s a system that allows you to build agents which can monitor all sorts of things for specific kinds of activities or events, and also do things as a result of those events. It’s certainly not as easy to use as IFTTT, but it’s not that difficult either, and once you’ve got the hang of it, the system has a lot of power and flexibility, because you can string together multiple agents to process events step-by-step.
Huginn1 also comes with a very handy script to deploy to Heroku: an easy-to-use service for deploying web applications without having to mess around with server settings. I have had a Heroku account (the free tier) for a while, without really using it, so it seemed like a good opportunity to put it to use. And it worked really well. Heroku may be more expensive than plain old hosting options, but for an impatient hobbyist like me who just wants to get to the fun or running something without all the tedious server wrangling, it’s absolutely brilliant. For now, Huginn is running well for me on the free tier (I used information on the wiki to set it up to minimise memory usage), but if I end up paying for the cheapest paid plan, I think it would be worth it.
So what am I doing with all this agent-running power? I set up a number of agents to watch for new events in RSS feeds (for my Pinboard, Goodreads and Letterboxd accounts), extract the useful information from the feed, format it, and then create a post of the appropriate kind and publish it on Tumblr. The formatting part is the really clever bit, and something that (as far as I understand it), you can’t do with IFTTT. For example, I used to have to copy, paste, clean up and then post my Goodreads reviews manually, because the RSS feed provides a rather clunky format for the information.
My Goodreads RSS agent gets new events in the feed, then passes them to a Goodreads formatter. This uses some regular expression magic in ‘matchers’ to pull out the relevant bits of the feed, paste them into a text string in the format I want, and then output this information in the form of JSON keys and values. These can be whatever you want, but in my case are title
and body
, which I can then pass to the Tumblr posting agent, which posts them for me on Slipstream. This is the formatting agent, it all its regex glory:
The formatting uses Liquid tags (the curly braces), which allows you to do some rather neat things. For example, the image link for the book cover that is included in the description part of the RSS feed points to the smallest thumbnail. However, by swapping out the ’s’ suffix of the ID code in the URL for a ’l’, you can get the largest version of the image. The {% regex_replace %}
command above does just that, taking the cover image fragment I have extracted with the matcher, cutting the URL apart, swapping out the ’s’ for a ’l’, and then glueing it all back together again. Is there any geeky task more satisfying than getting a regular expression to work perfectly? I suspect not.
I’m really happy with the way it works. Once you’ve set it up, it just potters away in the cloud, doing its stuff. I haven’t yet linked up my Flickr or Instagram accounts, as I need to think about how I want to handle them, particularly as Instagram doesn’t offer an RSS feed as far as I know. There are agents that can deal with APIs of your choosing, in which you construct GET
or POST
requests, so that’s probably what I’ll do.
I’m really enjoying building my own system to handle these micro blog type things, and it has encouraged me to think about taking the next step and building a Tumblr-like micro blog (with an API so I can post to it from Huginn). Currently, I’m thinking about using the Python web framework Flask, because I’m slightly familiar with it, and it is a nice clean, minimalist framework. Free services like Tumblr and Instagram are easy to use and convenient, but both are starting to become obnoxiously cluttered with adverts, features I don’t use or want, and things flashing at me. I had let both accounts lie fallow for quite a while and going back to them now, the experience as a user has got substantially worse (particularly for Instagram). Adverts, ‘stories’ (whatever they are)2, and users you might like to (but probably don’t want to) follow are shoved in front of your eyeballs constantly. If it was possible to pay for an account that let you avoid these things and just look at nice (static) pictures posted by people you follow, that would be fine, but you can’t. It’s a real shame, because I do like the social aspects of both.
Anyway, I suspect this is part of an ongoing (and probably long) project, but it’s a fun thing to plan.