#!/usr/local/bin/python #-- # scilookup.cgi: Look up a six-letter bird code using the MySQL # nomenclature database # $Revision: 1.1 $ $Date: 2001/05/27 02:14:42 $ #-- # This script handles the form lookup.html, which has these elements: # abbr: Six-letter bird code to be looked up #-- from types import ListType # To check for lists import cgi # Main CGI handler import string # Standard string functions import hier, txny # Taxonomic hierarchy and taxonomic database from showtaxa import * # Function to display taxon with ancestors # - - - s c i L o o k u p - - - def sciLookup(sci): """Look up `sci' in the nomenclature database and display its meaning. [ if sci is a string -> if sci is a scientific name defined in the nomenclature database -> +:= sci + related common name else -> +:= error message in HTML ] """ #-- 1 -- # [ if taxonomy and hierarchy databases can be opened -> # h := the Hier object for the hierarchy database # tx := the Txny object for the taxonomy database # else -> # +:= error as HTML # return ] try: h = hier.Hier() tx = txny.Txny(h) except Exception, detail: print "

Database access error: %s" % `detail` return #-- 2 -- # [ if sci is a scientific name in tx -> # taxon := the Taxon object for that sci. name # else -> # +:= error as HTML # return ] taxon = tx.lookupSci ( sci ) if taxon is None: print "

Scientific name `%s' is undefined." % sci return #-- 4 -- # [ +:= taxon with ancestors as HTML ] htmlTaxon ( taxon ) # - - - - m a i n - - - - - form = cgi.FieldStorage() # Get the form object print "Content-type: text/html" # Print the required header for HTML print # Blank line to signify end of headers title = "Scientific name lookup" print "" print "" print " %s" % title print "" print "" print "

%s

" % title try: sci = form["sci"].value sciLookup ( sci ) except KeyError: print "

You must supply a scientific name." print "" print ""