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.
|Termite-Inspired Autonomous Robotic Construction Crew|
|Home Security With Toy Robots|
|Bird Buggy: a Parrot Driven Autonomous Vehicle|
|Replacing Robots With Humans Makes Toyota More Efficient|
|Rubik's Cube Solving Machine|
|"Is meant to produce more energy than it consumes."|
|“We have to forget steel as a core employer.”|
|“It’s not something you would expect to see there and not something we’ve seen there before.”|
|“Drone carrying defibrillators could begin operating in Sweden.”|
|Making a Movie Inside a Video Game|
|"Its tilted axis makes orbit, showing the position of the sun and the time."|
|"The first to target civilians and the first such malware built to target a nation’s power supply."|
|"Technological transformation first reduced the income of the populations for decades, although societies became wealthier in the long term."|
|“Making paper out of stone.”|
|It's a Commercial About a Sweater|
|A Simple Task for CRISPR|
|“Lights-out factory devoid of human labor”|