#!/usr/bin/python
print "Content-type: text/html\n\n"
from string import *
from re import *
from time import *
import os
import cgi
form = cgi.FieldStorage()
# Header
print """
Danny Adams
Danny Adams' Photo Album
"""
# Defintions
this_dir = "/home/dda/public_html/album/"
this_url = "index.py"
album_file = "album.dat"
# Informational
cats = {}
picts = {}
viewing_cat = ""
# Show Image
def show_image( image ) :
global viewing_cat
for k in picts.keys() :
l = picts[k]
indx = -1
for i in l :
indx = indx + 1
if i[0] == image :
viewing_cat = k
print "" + k +"
"
print ""
print "
"
print i[1] + ""
print "
"
if indx > 0 :
name = sub(".jpg", "", l[indx-1][0] )
print "PREV "
print " | "
if indx < len(l) -1 :
name = sub(".jpg", "", l[indx+1][0] )
print "NEXT "
print " | "
print "
"
# List Images In Cat
def list_images( cat ) :
print "" + cat + "
"
# We make lots of 3 column tables so render happens faster.
count = 0
for image in picts[cat] :
count = count + 1
if count % 3 == 1 : print "",
name = sub(".jpg", "", image[0])
print "",
print " ",
print " ", str(count), ". ",image[1] , " | "
if count % 3 == 0: print "
| |
"
# If there's cells left, draw it
if count % 3 != 0 :
print " | " * ( 3 - ( count % 3 ) ), ""
# Print all the categories
def print_categories() :
print "Danny Adams' Photo Album
"
print "The following sections are in the photo album:"
print "
"
list = map( None, cats.keys() );
list.sort()
for name in list :
print "- " + name + " (", cats[name]," pictures )"
print "
"
# How to process lines in the album
def process( line ) :
line = line[ 0:len(line) - 1] # Remove newlines
x = split( "\|", line, 0)
file = ""
category = "Unfiled"
description = "No Description"
if len(x) > 0 and len( x[0] ) > 0 : file = x[0];
if len(x) > 1 and len( x[1] ) > 0 : category = x[1];
if len(x) > 2 and len( x[2] ) > 0 : description = x[2];
# Add the categories to the list
if len(file) > 0 :
if cats.has_key(category) :
cats[category] = cats[category] + 1
picts[category].append( (file, description) )
else :
cats[category] = 1
picts[category] = [ (file, description) ]
# Process the album
album = open( album_file, "r" )
# Read the album into memory
while 1:
line = album.readline() # Get a line
if not line : break # EOF? We're done
process( line )
album.close() # Close
# Determine what to do
if form.has_key( "cat" ) :
list_images( form['cat'].value )
elif form.has_key( "image" ) :
show_image( form['image'].value )
else :
print_categories()
# Trailer
print """
"""
# djpeg -scale 1/4 <$f | cjpeg >`basename $f .jpg`-small.jpg