[Tutor] random file rotation program
Kirk 'Deliberatus' Bailey
idiot1@netzero.net
Tue Mar 25 23:47:06 2003
OK, I have used a program in C to rotate banners and 'fortunbe cookies'
for a lonmg time, but I just took a stab at writing one in python to do
it for me. Here is my first jab at it.
#!/usr/local/bin/python
# the previous line MUST be the first line, and MUST point at your
server's
# python interpeter!
#
# cookie.py (C)2002 Kirk D Bailey
# Released under the GNU GPL.
#
import os.path, string, sys, random
#
# targetfile = sys.argv[1] try this later when basic is working.
targetfile='cookiejar'
#
#----v----1---v----2---v---3----v----4----v----5----v----6----v----7----v----8
#
# use this next line if you are using ssi with the 'include' tag.
# if you use the 'exec' tag, comment out the next line.
print "content-type: text/html\n\n"
#
# invoke in a web page as:
# <!-- include virtual="/cgi-bin/cookie.py" -->
#
print '<!-- random cookie by COOKIE.PY -->'
print '<!-- from http://www.tinylist.org -->'
#
def gangstrip(thing): # ok, everybody STRIP!
index=0 # This strips out whitespace
chars
while index < len(thing): # define exit
thing[index]=string.strip(thing[index])
index=index+1 # increase the counter
return thing
#
if os.path.exists(targetfile):
f1.open(targetfile,'r')
cookies=gangstrip(f1.readlines())
f1.close()
else
cookies = ['ERROR:file "' + targetfile + '" not found or
unavailable.']
#
print random.choice(cookies)