Twitter to Fortune - Converting Tweets to UNIX Fortune

Posted on October 01, 2010

Warning: this post is not very security related…

Do you follow any infosec people on the Twitter that consistently make you laugh? Or whose tweets seem strangely proverb-like? (you get to define strange).

I follow a few such tweeps like and the problem is their tweets get lost in the stream, unlikely to resurface after an initial flurry of retweets.

As a fan of ye olde UNIX fortune program – but often not the fortunes themselves – I wanted to inject some twitter wisdom (!). Instead of receiving a famous quote or not-so-funny joke from one of the existing fortune data files, I wanted to create my own with tweets from one of my favourite twits.

A short time later and tweet2fortune.py was born.

This python script is simple:
– you tell it which (public) twitter handle to grab tweets from
– it grabs the tweets, filters out retweets/replies and tweets containing URLs
– then formats them in fortune(1) file format (a % separated text file essentially)

All you need to do is redirect the output to a file using standard UNIX redirection, generated a fortune index file and you’re set:

$ tweet2fortune.py jack_daniel > jack_daniel_tweets
$ strfile jack_daniel_tweets

Now, anytime I want to hear a nugget of knowledge from Jack Daniel, I just run:

$ fortune jack_daniel_tweets

and I get…

I know, let’s simultaneously panic and fawn over Stuxnet while our
domain admin pw is password, and our CMS is a default install.
— @jack_daniel

In reality, I run fortune from my ~/.bash_profile so I receive a twitter powered fortune each time I log in.

The script is simple and can easily be adapted for more use-cases, I encourage you to tweak away.

Enjoy ;-)