[ale] Python help for sig generator

Trey Sizemore treysizemore at bigfoot.com
Sun Mar 16 09:16:33 EST 2003


On Sat, 2003-03-15 at 22:28, Joe wrote:
> Trey Sizemore <treysizemore at bigfoot.com> writes:
> 
> > I saw a post where someone had given a sample Python script to randomly
> > generate sigs pulled from a text file.  I copied the script and made it
> > executable, but the actual pulling of lines from the text file doesn't
> > seem to work (see below).  I am using Evolution for email.  Here is the
> > script (in my /home/trey
> > directory):
> > 
> > #!/usr/bin/python
> > 
> > # change this to point to your file of quotes
> > aff_file = "/home/trey/quotes.txt"
> > 
> > import string, random
> > 
> > # hack this at will
> > print "---<br>"
> > print "Cheers,<br>"
> > print "Trey<br>"
> > print "---<br>"
> > print "<br>"
> > print "Today's Affirmation (selected automatically just for you):<br>"
> > print "<br>"
> > 
> > # cryptic python stuff which pulls a line from a text file
> > # at random
> > affs = file(aff_file).readlines()
> > aff = affs[int(random.random() * len(affs))].split("\n")[0]
> > 
> > # print the randomly selected line
> > print aff
> 
> If you run the Python script from the command line (eg
> "python theScript.py"), do you get a random quote? (You
> should, the code looks fine, provided each quote is
> just one line long.)
> 
> Therefore, the problem is likely in the way you've configured
> your mail client to use the script. I have no clue about
> Evolution, sorry :-( But it should be something obvious.
> Either your client directly supports using an outside executable
> to generate siggage, or it doesn't; if it doesn't, you'll
> probably need to use a named pipe (or FIFO, First-In-First-Out).
> 
> I used to do this with "fortune". I created a named fifo using mkfifo,
> and ran a script that waited for the fifo to become writeable. When
> that happened, it piped the output of "fortune" into the fifo,
> followed by a ^D.  I told my email client that the file containing my
> sig was the fifo. The email client thought it was reading a regular
> file for my .sig, but each time it read that file, it got a different
> fortune.
> 
> HTH,
> 
> -- Joe Knapka
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale

Here is the command line output:

trey at libranet:~$ python signature.py
---<br>
Cheers,<br>
Trey<br>
---<br>
<br>
Today's Affirmation (selected automatically just for you):<br>
<br>
Traceback (most recent call last):
  File "signature.py", line 19, in ?
    affs = file(aff_file).readlines()
NameError: name 'file' is not defined

It looks as if the variable IS defined.  The file source file is
quotes.txt located in /home/trey.  Hmmmm.

> 
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list