Twitter bots is something I like a lot. Up until now, I haven’t ventured into making one myself, which is a bit unfortunate because earlier, the process of getting an R/W access for a bot was much easier. Anyway, thanks to a level-headed blog posting by Dalton Hubble, I managed to grasp the basics. Timo Koola and Duukkis, central figures in Finnish bot scene, and friendly guys at that, gave helpful advice too.

The last push forward came from abroad. Early October, Andy Teucher announced that he had published a bot that used the twitteR package, something I had in mind too. My turn!

Tweet by Andy Teucher on his R-based Twitter bot

Technicalities aside, there was also the question of What?

My pick was to start with job-related text snippets, touting altmetrics.

This summer, Impactstory showed a fair amount of generosity. Although their profiles ceased to be free of charge, they gave away free waivers – and I was lucky to get one for the experimental profile showing a sample of Aalto University research outputs.

The JSON file, linked from the landing page, is packed with data. From the many possibilities, I decided to first focus on what new there is since last week. New GitHub forks, video plays, Slideshare views etc. The same information is visible on the Impactstory profile. It’s the small flag with a + sign and number, just after the metrics label.

Impacstory flag showing new activity since last week

It took a while to get familiar enough with the JSON, and how to traverse it with R. Modelling the tweet was another thing that needed a number of test rounds. The last mile included e.g. finding out how to fit in the URL of the product. In here, Andy’s GitHub repo of the Rare Bird Alert Twitter Bot came to rescue: he had done the URL shortening with Bitly.

I had nurtured the fancy idea of (somehow) making use of Unicode block elements like Alex Kerin has done. However, after some experiments in my test account I gave up. They might come handy in showing a trend, though.

Test tweets with sparklines

Setting up a new Twitter account for the bot was of course easy, but even here was something new to learn. Did you know that you can have multiple, custom Gmail address variants within one account?

So, here is the WeeklyMetrics Twitter bot in its present shape. What is still on a test phase, is running the R script successfully in batch. The cron scheduling seems to work OK, but as Eric Minikel points out at the end of his thorough posting, making the script robust asks probably for some tryCatch blocks. The Impactstory server could be temporarily on hold, Bitly’s likewise. At the moment, my script assumes happily that all is safe and sound in the universe.

The R code

Posted by Tuija Sonkkila

About Tuija Sonkkila

Data Curator at Aalto University. When out of office, in the (rain)forest with binoculars and a travel zoom.
This entry was posted in Data, Learning and tagged , , , , . Bookmark the permalink.

Comments are closed.