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.
|A_FAB: Mobile 3D Printing Robot as a Factory Operative|
|Autonomous Vehicles in Operation in China|
|South Korean Shipyard Workers to Wear Robotic Exoskeletons|
|"Automation will disrupt millions of Canadian jobs, not far in the future, but in the next dozen years."|
|Brain of Earthworm Recreated in Software and Embedded in a LEGO Robot|
|Everything We've Learnt About the Surveillance State|
|How to Avoid Jury Duty|
|Go the Fuck to Sleep: A Children's Bedtime Book|
|“He portrays these abandoned malls as apocalyptic ruins.”|
|“The cost could be so near to zero it will effectively be free.”|
|Japanese Robot Serves Ice Cream From Inside a Vending Machine|
|“Put words between buns.”|
|“Rejuvenation is Finally an Industry.”|
|Google Map Shows You the Most Photographed Areas of the World|
|Sensually Retro Illustrations by Simone Massoni|
|Cure for Gayness? There's an App for That|
|Good Fucking Design Advice|