#!/usr/bin/perl # A Perl proof-of-concept written by Adam Lawson. # This is a simple command line twitter status updating script for Perl. # There is nothing fancy here, just a straight posting mechanism. # Upon calling cURL, if you screwed something up (usually user name or password), # you'll notice that nothing uploaded. # Below is an example of an UNSUCCESSFUL attempt to post: # ------------------------------------------------------------------------------- # % Total % Received % Xferd Average Speed Time Time Time Current # Dload Upload Total Spent Left Speed # 100 141 100 141 0 0 633 0 --:--:-- --:--:-- --:--:-- 0 # ------------------------------------------------------------------------------- # Note how Total Time, Time Spent, and Current Speed are blank or 0. # Below is an example of an successful attempt to post: # ------------------------------------------------------------------------------- # % Total % Received % Xferd Average Speed Time Time Time Current # Dload Upload Total Spent Left Speed # 100 1788 100 1788 0 0 745 0 0:00:02 0:00:02 --:--:-- 1342 # ------------------------------------------------------------------------------- # Note how Total Time, Time Spent, and Current Speed are NOT blank or 0. # These are functions the return from cURL, so I can't take credit for it. # Other than the vanilla installation of Perl, we are relying # on the Term::ReadKey module (available from CPAN, but likely # already installed) and the cURL library (which depends on your # distro, but can be obtained from http://curl.haxx.se/ if you # need it). You may also need/want to "chmod a+x tweet" so you # can execute this script by simply typing "./tweet". That makes # things much simpler. Ok, enough jibba jabba -- on with the show! use Term::ReadKey; # Include this module so we can hide the password. print "What are you doing?\n"; # Prompt for status. chomp($status = ); # Collect status into a scalar and chomp it. print "What is your user name?\n"; # Prompt for user name. chomp($user_name = ); # Collect user name into a scalar and chomp it. print "What is your password?\n"; # Prompt for password. ReadMode 2; # Turn off screen updating (accomplished by including the Term::ReadKey module). chomp($password = ); # Collect the password into a scalar and chomp it. ReadMode 0; # Turn screen updating back on. print "Posting to Twitter...\n"; # Prompt that we are prepared to begin the posting script. # Build a scalar in the proper cURL syntax and drop in the other variables where appropriate. $post_string = "curl -u " . $user_name . ":" . $password . " -d status=\"" . $status . "\" http://twitter.com/statuses/update.xml"; # Execute the command created by our string, which will tell call cURL and post it to Twitter! `$post_string`;