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.
|Boston Dynamics' Spot|
|Botlr, a Robotic Bellhop|
|"Expect to see more armed robots on American streets."|
|Robotic Hands that Can Grab Anything|
|Campaign Wants Ban on Autonomous Killer Robots|
|"Frozen brains could be thawed and inserted into a donor body."|
|"It’s appealing to imagine a world where artificial wombs grow babies."|
|"Have you ever pondered why we itch in the first place?"|
|"Academics who study basic income said the pilot gives a chance to see how the idea plays in a changed economy."|
|Google's Self-Driving Cars Giving Rides to the Public|
|Head Transplant Hailed a Success|
|"You look in the mirror and see your body and your face and you think that’s you—but that’s really just the machine you’re riding in."|
|"This created a bubble, and like housing, that bubble has now burst."|
|Religious Loophole to Turn Lights On and Off During Shabbat|
|Where AI is Currently At|
|Boston Dynamics' Fast Running Wildcat Robot|