- No queue
- No automatic tweets
- No automatic Quicklinks posts
In this post I’ll look at this Twitter thing.
I want, that a new tweet gets tweeted each time I publish a new post to instant-thinking.de. While running on Wordpress, a nice plugin handled this for me. But, well, there are probably a few thousand other ways to do this, even for a static HTML-site.
One of the easiest surely is Twitterfeed. Just point this free service at your RSS-feed and let it forward your postings to Twitter and/or Facebook. They even got some tracking going on.
But I did it yet another way, by using a tiny Ruby script which lives on the Mac mini at home. If you’re interested in the nitty gritty details, be sure to follow me after the click…
Still with me? Good.
The script is based on twitterscript2 by Michael Morin. It was modified by me to use the current OAuth-authentication used by Twitter, use YAML instead of Marshal to serialize and deserialize data and to better suit my needs in general.
The whole thing consists of the script itself,
it_tweet.rb, a config
config.yml, a cache file4 named
a LaunchAgent which goes by the name of
So what does it do?
The script gets called every five minutes by the LauchAgent. It loads some gems and reads it’s config variables from the config file.
It then proceeds to load the configured RSS-feed from the web and turns it upside down, to have a look at the oldest entry first. If the publication date of the entry is newer than the timestamp from the last run of the script, it’s title and link get extracted and tweeted as a New Blogpost tweet to my Twitter account. Then the script sends me a mail, telling me that it just tweeted a new tweet and updates the timestamp to the date and time of the just tweeted entry.
It then sleeps a minute, before it continues with the second oldest feed entry.
If the cached timestamp is newer than the currently processed feed entry no tweeting, mailing or sleeping takes place, the script simply continues to the next feed entry.
So on the first run, you end up with all your feed items getting tweeted with a pause of 60 seconds between each tweet5. After this initial tweetstorm things settle down and become much saner for you and your follower.
And that’s about it, really.
It is not always necessary to use a fancy service on the Internet to get things done. Sometimes all it takes is a trusty Mac mini running a customized script.
I also learned, that for every major problem one could encounter when starting to write a script, somebody probably released a nice rubygem suited to help you. The twitter gem makes tweeting trivial, the mail notification would be much harder to code, without pony.
How to tweet along
If you decide to use it, just go ahead and
clone from Github to some
place on your computer.
You then have to remove the
.example extension from the config file and from
plist, to make them usable.
The feed-variable in
config.yml obviously gets filled with your feed-address.
You’ll have to obtain your Twitter-OAuth-credentials by registering an app at Twitters developer site and copy & paste them to your config file.
The mail settings are pre-configured for
Google-Mail, if you got a Gmail-account7 you’ll
simply have to insert your
firstname.lastname@example.org address and password in
smtp-fields. Configuration for any other mail-provider is
left as an exercise to the reader and will probably require some work on the
pony section in the script itself…
When you finished the config you can execute the script. It should start to tweet the items of your feed to your Twitter-stream.
To automate the process, you’ll have to move the
~/Library/LaunchAgents and change the absolute path to
wherever you put it.
Also: It should be no problem to run the script on a Linux-system. In this
case, you’d have to make a
cron-entry instead of a LaunchAgent. I’ll continue
with the OS X way because that’s what I used.
So, you load the LaunchAgent with
And check that it got loaded:
0 is the exit code of the last run. A zero is fine, any other number is bad.
After five minutes you should see some activity in your
If the script encounters new feed entries, it will tell you about these in the logs, too.
Congratulations, you just set up your very own RSS-to-Twitter app with mail notifications.
I’m pretty sure there are some nuisances with my english, too. Let’s see how it turns out…↩
Stands for If This Then That. I really like this acronym…↩
For storing things like filenames, feed-URL, OAuth- and SMTP-credentials↩
to save a timestamp of the last run↩
Unless you uncomment the tweet in the script, maybe I’ll add a
no-tweet-option in a future version↩
And who doesn’t?↩