[Tutor] web tool

Kirk Bailey idiot1@netzero.net
Mon Jun 9 20:21:02 2003


Sometimes it is good to see what images you have stockpiled on a web server. I wrote a 
script to display them for you. You can see it's results at
http://www.listville.net/cgi-bin/images.py
and here is the entire script. Note that you must modify it if you have a seperate 
images directory off of the web directory, a reccomended procedure.

ns# list images.py
Listing of file images.py in directory:/www/www.listville.net/cgi-bin

#!/usr/local/bin/python
import glob, os
os.chdir('..')  # assuming this is is in the web cgi-bin
#               # we go up the tree a level to the web directory.
print 'Content-type: text/html'
print
path=os.getcwd()
print 'path='+path+'<P>'
print "<head><title>IMAGES IN WEB DIRECTORY</title></head>"
print '<body bgcolor="A0A0A0"><P>'
print '<CENTER><H1>IMAGES IN THIS WEB DIRECTORY</H1><p>'
images=glob.glob('*.gif')
images=images+glob.glob('*.jpg')
images=images+glob.glob('*.png')
for item in images:     #this gets tricky.
         print item,'<br><img src="../'+item+'"><P>'     #the browser thinks it is
print '<P><br></body>\n</html>'                         #still talking to the cgi-bin!
#
# that's no good, if the images are in the web directory.
# if the images are in the /images directory, you need to change the chdir
# command to get to it, and change the path declaration to
# '../images/' in the print statement.
# But done this way, you do not have to hack the program (much) and it is a useful
# image inventory tool.

ns#

NOTE that the receiving browser thinks the /cgi-bin/ is the current directory, and sends 
in the image requests as
www.yourdomain.foo/cgi-bin/(imagename)
UNLESS
you tell it differently,. You COUKD declare an absolute patn, such as
http://www.listville.net/swirlies.jpg
OR
use relative addressing, which is what I did, and say
"../(imagename)
OR
"../images/(imagename)
If they live in the images dir. IF they do, you have to modify the chdir command:
os.chdir('../images')
ought to do it.

A silly little python tool for the webmaster.



-- 

end

Cheers!
         Kirk D Bailey
                               think
http://www.howlermonkey.net/ +-----+ http://www.tinylist.org/
http://www.listville.net/    | BOX | http://www.sacredelectron.org/
                              +-----+
"Thou art free"-ERIS          think    'Got a light?'-Promethieus

.