With a little bash script, the posting service dlvr.it and Linux's fortune program, we created a simple little bot that annoyingly spews out a random fortune of 140 characters or less every 15 minutes. You can see the bot's Twitter stream here. If you are on Twitter, you could follow the account but... consider that you'd be getting four random fortunes an hour -- that's almost 100 tweets a day. Some may not even make any sense. It's your call.
A few nights ago I was searching the ether to see what would be required to have the server report warnings, issues and statistics (hd space, load, etc.) via Twitter. The advantages -- aside from a high neat factor -- would be that we'd get immediate, steady updates through our respective Twitter streams. I don't check my email often, but for some reason I always have Twitter on -- and can even selectively have particular tweets sent straight to my phone at any time of the day or night.
Unfortunately, it turns out that in order to do so, you need to have a good understanding of Twitter's API and access policies, which went a little beyond what I had in mind of doing -- I'm lazy.
So why not just use a simple RSS feed? If I can feed this website's RSS feed to Twitter, Identica and Facebook, I could probably use the same system. And so, with a little bash script, I created an RSS file that would be generated every fifteen minutes via a simple cron job running through the www-data user. The script looks like this:
echo "<?xml version='1.0'?><rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>" > /var/www/bottune.xml
echo "<channel><title> /usr/games/fortune </title><link> http://con.ca/ </link><language> en-us </language>" >> /var/www/bottune.xml
echo "<copyright> Capital of Nasty Electronic Magazine ISSN 1482-0471 </copyright>" >> /var/www/bottune.xml
echo "<description> A quote every 15 minutes. </description>" >> /var/www/bottune.xml
echo "<atom:link href='http://con.ca/rss/rss.xml' rel='self' type='application/rss+xml' />" >> /var/www/bottune.xml
echo "<item>" >> /var/www/bottune.xml
echo "<title>" >> /var/www/bottune.xml
/usr/games/fortune -s -n 140 >> /var/www/bottune.xml
echo "</title>" >> /var/www/bottune.xml
echo "</item>" >> /var/www/bottune.xml
echo "</channel>" >> /var/www/bottune.xml
echo "</rss>" >> /var/www/bottune.xml
As you can see, it's not rocket science. You'll notice the fortune command has -s for short and -n 140 to limit the number of characters. Also, I only used one > in the first line ( [...] > /var/www/bottune.xml) so the XML file is recreated from scratch at each turn.
After that, I created a Twitter account -- which took longer than writing the above script because it seems that all the good names are taken -- and linked it with dlvr.it. Every 15 minutes, dlvr.it checks the RSS XML file, polling the quote in there and automatically posting it on Miss Fortune's Twitter account. And that's it.
You can potentially replace the /usr/games/fortune/ command with any other Linux command to your liking and have it pump out that information directly to a Twitter stream.
Useless? Totally. Neat? You betcha. But it doesn't take much to amuse a nerd like me.
|Betty, the Robot Manager|
|7-11 Delivers Slurpees by Drone|
|“A self-learning robot could be handy for exploring distant planets, too.”|
|Study: Humans Like Being Ordered Around by Robots|
|Garbage Sorting Robot|
|Garbage Sorting Robot|
|"There’s a galactic gold rush brewing."|
|Making a Movie Inside a Video Game|
|Fast, Clean, Cost-Effective Metal 3D-Printing|
|“What if energy generation was a consumer electronic you could order off Amazon?”|
|"A helpful guide created by an unqualified individual."|
|Google Map Shows You the Most Photographed Areas of the World|
|"You only need about 100 miles by 100 miles of solar panels to power the entire United States."|
|“Robots should be fitted with an 'ethical black box' to keep track of their decisions.”|
|"An unabashed love letter to the 1982 motion picture Blade Runner."|