char1es.net

twitter is the new finger (a bedtime story for little hackers)

March 9th, 2008

Once upon a time there was an operating system philosophy called Unix. Unix was the operating system of all the good people at universities and colleges. If you wanted to a use a computer at school there was only one computer to use, a Unix machine, and everybody had an account on the same Unix server and you accessed it with a terminal. People with accounts on the machine were called users and all your files were stored in your home directory. The amazing thing was you never had to carry around a computer and you could get to them whenever you had access to terminal. Unix made it easy to share, it made sure everybody was nice. Pale men in dark rooms made sure everything worked, most of the time. The happy little code monkeys wrote services like sendmail that allowed users to send electronic messages to each other, talk so they could chat and finger so they could see was online. finger even checked a file in you home directory for a file called .plan that you could leave messages about what you were doing or going to be doing when you were away. Configuration files in Unix always had a . in front of them so you didn’t see them unless you really looked for them with ls -la . And life was good. Then the Personal Computer came and made it difficult to do all the things that worked well on Unix. People had to maintain their computer and worry about nasty things like bugs, viruses, worms and blue screens of death. Nobody used finger anymore. And people were not happy. Then one day the World Wide Web was invented, people decided that they didn’t like to maintain their own data anymore so they used software on the web like gMail to store all their email. The software code monkeys wrote things like Instant messenger so you could chat and twitter so you could see what your friends were doing. A silly little code monkey named Nathan even wrote a little perl program to sync the .plan file with twitter. So twitter was like finger. And once again people could access their data whenever they had access to a terminal. Except now we call terminals apple macbook pros. And everybody was happy except the blue screens of death. They went and sulked under the overpasses leading away from Redmond.

So what is the moral of the story? Well the moral of the story is that nothing is new under the sun, and the more things change the more they stay the same.

Code Follows…

#!/usr/bin/perl
#Program: twitterd
#Author: Nathan Charles ncharles at gmail dot com
#Version: 0.1
#This program watches .plan file in your home directory and updates
#your twitter account with the contents of that file when it changes
#
# This program has no warranty to the full extent of the law

use File::Monitor;
use Getopt::Long;
use Net::Twitter;
use POSIX ‘setsid';

#CONSTANTS
use constant TWUSER => “twitterusername”;
use constant TWPASS => “twitterpassword”;
use constant TWPLANINT => 60;

sub usage {
print “usage: twitterd [-d]\n”;
print ” -d, –daemon run in background”;
exit 1;
}
sub daemonize {
open STDIN, “/dev/null”;
open STDOUT,”>/dev/null”;
open STDERR,”>/dev/null”;
exit if fork > 0;
setsid;
exec(“twitterd”);
}

sub twitterplan {
my $twit = Net::Twitter->new(username=>TWUSER, password=>TWPASS );
open(PLAN, $file);
@lines = <PLAN>;
close(PLAN);
print @lines;
$result = $twit->update(@lines);
print $result;
}

sub watchloop {

my $loopy = 1;

my $monitor = File::Monitor->new();
$home = $ENV{‘HOME’};

$file = “$home/.plan”;
$monitor->watch($file, \&twitterplan);

$monitor->scan;

my @changes = $monitor->scan;
while ($loopy )
{
@changes = $monitor->scan();
sleep TWPLANINT
}
}

MAIN:
{
my $daemon = ”;
GetOptions (‘d|daemon’ => \$daemon);

if ($daemon) {
daemonize();
} else {
watchloop();
}
}

- ❦ -
2 Responses to “twitter is the new finger (a bedtime story for little hackers)”
  1. $ finger travalas@twitter@any.io

    — Dan Moore[c]

  2. […] a while ago I decided that twitter is the new finger albeit more palitable for the masses and wrote twitterd in perl. I’ve been using this to […]

    — twitterd in Python | char1es.net[c]

Leave a Reply