TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:1872] Is this hard to do?



In a message dated 98-10-21 00:29:54 EDT, you write:

<< There are two related things I'd like to setup on my linux box. One is a
 script (cgi?) that will show a random gif from a list on my web page. I
 downloaded a chi script that did this from linux banners page, but it
 doesn't work, and I don't know how to debug it. (netscape just gives me
 the error). I can send the cgi script if someone wants.
 
 The other is to have my e-mail signature show a random quote from a list
 each time I send an e-mail. I don't know how to do this, except that it is
 the same concept as with the web/cgi script. >>

Here is a script that will show up a random image from a list.

Set up imagedir which should contain all the gif files for your image banners.
It should only have the image files and nothing else. Right now it can only
do gifs, but you can change it to do jpegs on the fly or I can help you change
it
if you like.

Set up the default image just in case something breaks this will show up.
And change /usr/bin/perl to wherever your perl actual resides.

If you like I can take a look at the script that you already have and see what
is wrong with it.

Point your browser to a few "fortune cookies" on linux at
http://www.stip.fr/lfce.html.

The second problem is to do with which mail program you use. One easy way
to do this is to write a wrapper for your mail program which first creates a 
.signature file using a random quote and then starts your mail program.

But then your signature remains the same as long as you do not exit and
restart.
I am not familiar with pine/elm but they might let you create signature files
dynamically.

Here is another idea which I am not sure is possible but might be interesting.
Write a monitor program that monitors if the .signature file is opened.
Each time it notices an open on the signature file it updates
the signature file with something new. 

--
sandipan

---- Cut After this line.  --
#!/usr/bin/perl

#all images in the image directory.
$imagedir="/usr/local/www/data/banners";
$defaultimage="/usr/local/www/data/linux.gif";

sub show_image # filename
{
	my($file) = @_;

     #send the mime type, can make it intelligent to see what kind of image
file it is 
     #and then set the appropriate mime type.
    	printf "Content-type: image/gif\n\n";

      #Read the input file and print it to output.
	open( INP, "< $file" );
	while( read( INP, $buf, 1024 ) ) {
		print $buf;
	}
	close( INP );
}

#Open the imagedir and read the list of files in there.
if ( !opendir( DIR, $imagedir ) )
{
	&show_image( $defaultimage );
}
else
{
	#Read the image files and pick up a random one, This will only get the files
      # in the imagedir.
	@filelist = grep { -f "$imagedir/$_" } readdir( DIR );
	closedir( DIR );
	if( $#filelist < 0 )
	{
		#didnot find any.
		&show_image( $defaultimage );
	}
	else
	{
		$loc = rand;		#this will call srand.
		$loc *= $#filelist;	#Use it to index into the list.
		$loc = int($loc);
		&show_image( "$imagedir/$filelist[$loc]" );
	}
}

__END__

-- This is the end of the script. --