Megan Taylor

front-end dev, volunteacher, news & data junkie, bibliophile, Flyers fan, sci-fi geek and kitteh servant

Counting Tweets to Trigger an Email to Write a Blog Post

Like the old lady who swallowed a fly…

I’ve been feeling restless lately. Not enough coding getting done. Summer lull. Whatever. So when That Guy I Married said he wanted to be blogging more frequently, and had thought of a way to remind himself to do it, I perked up.

The concept: If you’re tweeting a lot during a short time period, chances are there is a blog post buried in there somewhere. So if there were a way to check the frequency of tweets in a certain time period, and trigger an alert if the frequency went over some limit, a blog post might get written.

The result: A little PHP script that can be run as a cron job. It uses the Twitter API to count how many tweets there have been since the previous date. (I would have liked to do it as number of tweets over the course of a few hours, but I couldn’t figure out how to do it without using a database to store the status ids.) Once the number of tweets has been calculated, it checks to see if that number meets the conditions for triggering an email. (In this case, 10 or more tweets since yesterday would trigger an email.) If the condition is met, That Guy I Married gets an email reminding him to write a blog post.

The code:

I’m setting up the cron job tonight, and I guess we’ll see how effective this is. As always, suggestions for improvement are appreciated.

August 1, 2012 | Comments Off on Counting Tweets to Trigger an Email to Write a Blog Post | Categories: Posts | Permalink

Comments are closed.