{ brad brace } on Wed, 26 Sep 2001 15:58:39 +0200 (CEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Nettime-bold] 12hr shell script



 ------------------------------ cut here ------------------------------
 #!/usr/bin/perl -w
 # $Id: get12,v 1.1 1999/02/19 17:03:28 trss Exp trss $
 
 # Get an image by FTP, possibly mangle it about, and place it on the
 # root window of an X workstation.  Use `--help' for brief docs, or
 # read the code.  Intended to be used with Brad Brace's 12hr-ISBN-JPEG
 # project <http://www.teleport.com/~bbrace/bbrace.html>: install it in
 # your crontab and enjoy.  Based on a shell script from Need To Know
 # <http://www.ntk.net/>, and written by Robin Stephenson <quux@usa.net>.
 
 use strict;
 use Getopt::Long;
 use URI::URL;
 use Net::FTP;
 
 ## configuration
 my($help, $verbose, $email, $URL, $image, $mangle);
 GetOptions("help"     => \$help,
           "verbose"  => \$verbose,
            "email=s"  => \$email,
            "src=s"    => \$URL,
            "dest=s"   => \$image,
            "mangle"   => \$mangle);
 if (defined($help)) {
     usage();
     exit(0);
 }
 
 
 # defaults
 if (!defined($verbose)) { $verbose = 0 } else { $verbose = 1 };
 if (!defined($email))   { $email   = "quux\@usa.net" };
 if (!defined($URL))     {
     $URL = "ftp://ftp.rdrop.com/pub/users/bbrace/12hr.jpeg"; };
 if (!defined($image))   { $image   = "/tmp/12hr-isbn-jpeg.jpeg" };
 if (!defined($mangle))  { $mangle  = 0 };
 
 # this is a bit clunky, and really easy to break  *shrug*  works for me
 my($DISPLAY) = $ENV{'DISPLAY'} || "unix:0";
 
 my($XMESSAGE) = '/usr/X11R6/bin/xmessage';
 my($XV)       = '/usr/X11R6/bin/xv';
 my($CONVERT)  = '/usr/X11R6/bin/convert';
 
 
 ## main program
 $URL = new URI::URL $URL;
 getfile($URL, $image);
 $mangle and $image = processimage($image);
 setbackground($image);
 
 if ($verbose) {
     my($date)=`date +"%l:%M %p %A %d %B"`;
     chomp($date);
     message($date, "Updated root window from\n$URL");
 }
 
 exit(0);
 
 ## subroutines
 # Print some basic usage information.
 sub usage () {
     print STDERR << "EOF";
 get12  [-verbose] [-email="your\@email.here"] [-src="URL of image"]
                   [-dest="/tmp/image.jpeg"]  [-mangle]
 
     --email        your email address: used to log you in to anonymous FTP
     --src          an FTP URL of an image file (see below)
     --dest         where the image file will be stored locally
     --mangle       post-process the image after it arrives (see source)
 
     URLs for the 12hr-ISBN-JPEG project are as follows:

     ftp://ftp.eskimo.com/u/b/bbrace/12hr.jpeg
     ftp://ftp.idiom.com/users/bbrace/12hr.jpeg
     ftp://ftp.teleport.com/users/bbrace/12hr.jpeg
     ftp://ftp.rdrop.com/pub/users/bbrace/12hr.jpeg
     ftp://ftp.pacifier.com/pub/users/bbrace/12hr.jpeg
 EOF
     ;
 }
 
 # Get the current picture from $URL by FTP and place in $dest.
 sub getfile ($$) {
     my($URL, $dest) = @_;
 
     if($URL->scheme ne 'ftp') {
         die("Not an FTP URL: $URL\n");
     }
 
     my($site) = $URL->netloc;
     my($file) = $URL->path;
 
     my($ftp) = Net::FTP->new("$site");
     $ftp->login("ftp", "$email");
     $ftp->get($file, $dest) or die("Couldn't get $URL: $!\n");
     $ftp->quit();
 }
 
 # Display a message in an X window (click to dismiss).
 sub message ($$) {
     my($title, $message) = @_;
 
     # primitive escaping of special characters
     $title   =~ s/\"/\\"/g;
     $message =~ s/\"/\\"/g;
 
     if (-x $XMESSAGE) {
         # This is a bit ugly: xmessage idea is from Jamie Zawinski's cid hack.
         my($command) = << "EOF";
 /usr/X11R6/bin/xmessage -display $DISPLAY -name "$title"                            -xrm '*Font: -*-lucida-medium-r-*-*-*-190-*-*-*-*-*-*'                          -xrm   '*Foreground: black'                                                     -xrm   '*Ba
 
 ckground: lightgreen'                                                -xrm   '*Command.Background: red'                                               -buttons ''                                                                     -xrm   '*Command.horizDist
 
 ance: 25'                                             -xrm   '*message.borderWidth:0'                                                 -xrm   '*Translations: #override <BtnDown>: exit(0)'                            "$message" &
 EOF
     ;
         system($command);
     } else {
         warn("xmessage not found in $XMESSAGE\n");
     }
 }
 
 # Mangle an image from the $image file in some interesting
 # NON-DESTRUCTIVE way.  Return the filename of the modified image.
 sub processimage ($) {
     my($image) = @_;
 
     # add a blue tint
     if (-x $CONVERT) {
         system("$CONVERT $image -colorize 0/0/40 $image.blue");
         return("$image.blue");
     } else {
         warn("no conversion performed\n");
         return($image);
     }
 }
 
 # Set the root window image to the image contained in the $image file.
 sub setbackground ($) {
     my($image) = @_;
 
     if (-x $XV) {
         system("$XV -display $DISPLAY -quit -root -rmode 5 -maxpect $image");
     } else {
         warn("xv not found in $XV\n");
     }
 }
                       
 
 
 
 __
 

 


_______________________________________________
Nettime-bold mailing list
Nettime-bold@nettime.org
http://www.nettime.org/cgi-bin/mailman/listinfo/nettime-bold