Publishing Tweets to a WordPress blog

With IFTTT losing Twitter triggers I figured I better do something if I want to keep reposting my tweets to this blog. So with the help of the inestimable Steve Morris I whipped up a little Ruby script that is meant to be run as a cron job; the results are visible as the previous seven posts here.

Requirements for using this script:

  • A Gmail account from which to send emails.
  • A Twitter developer account with an application set up so you have the necessary keys and tokens to use in the script.
  • OSX and will probably work on Linux as well, but as for Windows I have no idea nor do I have an interest in finding out (if you port it, feel free to tweet it to me and if it seems reasonable I’ll post it here). Note that OSX and Linux come with a sufficient Ruby to run this, though you may need to tailor the first line shebang to your installation.

I used two gems to power the script: Chris Kowalik’s gmail and Erik Michaels-Ober’s twitter. It’s possible I could’ve used Erik’s t Twitter command line gem and had an even simpler script but this seems fine for now.

The script has three main parts:

  • Configure Twitter and grab the most recent 20 tweets (the default is 20, which for me is more than sufficient).
  • Loop through the tweets in reverse order (to go from oldest to newest) and for the tweets made since midnight today mail them to WordPress.
  • Send an email (through Gmail) to your blog’s secret email address with a body containing the tweet short code plus the category, comments, and publicize shortcodes to properly configure the resulting post.

Next thing I’m going to work on is adding favorites to the script.

Update: Now does favorites too.