Abstract
This page sorta describes a Python/PostgreSQL application I wrote that generates a web page directory of school services for deaf students based on a user query. It isn't the best code in the world, (and some of the HTML that it generates is ugly) but novice developers may benefit from giving it some study.
The PROGRAMS below are copylefted under the GNU Public License (GPL). HOWEVER copying the DATA and the web pages generated from the data is not permitted without authorization from the GRI.
The following programs/schemas/whatevers comprise the bulk of a system for generating dynamic web pages from a PostgreSQL database using Python. The code isn't particularly pretty, but it should be fairly readable, with a bit of background
The Gallaudet Research Institute (GRI) (a division of Gallaudet University) and Rochester Institute of Technology's National Technical Institute for the Deaf (RIT/NTID) periodically publish the "College and Career Programs for Deaf Students" which is a directory of colleges and universities that offer programs for deaf students.
The information is collected by surveys sent out to as many schools as we can find. The survey covers things like the number of deaf students enrolled, the number of degrees awarded to deaf students, and services offered, as well as contact information, and major programs of study.
This go-around (the 11th edition, and the third time it's been on the web), we had a bit of ambiguity in the original survey form regarding contact information. So a follow-up form was sent out.
My boss designed both the survey, and the initial tables using
Microsoft Access 97. She also designed the layout of the book and
the general look of the web pages. I prefer working in Linux, and
avoiding Microsoft products as much as possible. I opted for
PostgreSQL, Python and Lout.
Lout is a document layout
system akin to TeX, LaTeX, et al. (Had I known about
ReportLab which
allows one to create PDF directly from
Python I might have opted for
that instead.)
The search engine was built from hacking a copy of the program that generated the PDF file.
In brief, the nine files below are:
To get an idea of what's going on, you can play with the engine from the on-line edition of the book. Select either "SEARCH PROGRAMS" from the banner at the top of each page, or "*** PROGRAM DESCRIPTIONS ***" from the bottom of the Table of Contents (to the left on the main page).
------------------------------------------------------------------------- -- NAME: main.sql -- AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> -- WHERE: Gallaudet Research Institute, Washington, DC 20002 -- LASTMOD: 2001.08.01 -- PURPOSE: This table provides details from the College and Career -- Guide, 11th Edition. It contains the information from -- the main survey form. There is an ambiguity in this form -- relating to contact information. The problem was corrected -- by sending a follow-up form and adding that data to a second -- table, (See table "contacts".) -- USAGE: select * from main where ...; -- DISCLAIMER: This started life as someone else's Microsoft Access (yeuch!) -- database, and isn't exactly the design I have chosen, but -- I'm stuck with it. -- -- Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ------------------------------------------------------------------------- create table "main" ( "entered" character varying(1), "id" integer NOT NULL, "comments" character varying(254), "name" character varying(50), "title" character varying(50), "department" character varying(75), "institution" character varying(60), "address_1" character varying(50), "address_2" character varying(50), "city" character varying(50), "state" character varying(2), "zip" character varying(10), "entry_detail" smallint, "inbook10" character varying(3), "enroll_deaf" smallint, "fulltime_ugdeaf" smallint, "parttime_ugdeaf" smallint, "fulltime_gdeaf" smallint, "parttime_gdeaf" smallint, "deaf_enrc" character varying(50), "primary_support" smallint, "deaf_program" character varying(75), "year_estab" smallint, "admin_50pct" smallint, "part_progr" smallint, "name_of_office" character varying(50), "program_director" character varying(50), "phone_nmbr_1" character varying(10), "phone_ext_1" character varying(6), "phone_type_1" smallint, "phone_nmbr_2" character varying(10), "phone_ext_2" character varying(6), "phone_type_2" smallint, "e_mail" character varying(80), "inst_web" character varying(80), "inst_type" smallint, "inst_gov" smallint, "inst_govc" character varying(50), "accred" smallint, "campus" smallint, "campusc" character varying(100), "lart2" smallint, "lart4" smallint, "gradp" smallint, "tech2" smallint, "tech4" smallint, "othpg" smallint, "voctrn" smallint, "othpgc" character varying(75), "maj_01" smallint, "maj_02" smallint, "maj_03" smallint, "maj_04" smallint, "maj_05" smallint, "maj_06" smallint, "maj_07" smallint, "maj_08" smallint, "maj_09" smallint, "maj_10" smallint, "maj_11" smallint, "maj_12" smallint, "maj_13" smallint, "maj_14" smallint, "maj_15" smallint, "maj_16" smallint, "maj_17" smallint, "maj_18" smallint, "maj_19" smallint, "maj_20" smallint, "maj_21" smallint, "maj_22" smallint, "maj_23" smallint, "maj_24" smallint, "maj_25" smallint, "maj_26" smallint, "maj_27" smallint, "maj_28" smallint, "maj_29" smallint, "maj_30" smallint, "maj_31" smallint, "maj_32" smallint, "maj_33" smallint, "maj_34" smallint, "maj_35" smallint, "maj_36" smallint, "maj_37" smallint, "maj_38" smallint, "maj_39" smallint, "maj_40" smallint, "ugftenr" integer, "ugptenr" integer, "gftenr" integer, "gptenr" integer, "enrc" character varying(100), "dorms" smallint, "local_tuition" double precision, "local_rb" double precision, "state_tuition" double precision, "state_rb" double precision, "other_tuition" double precision, "other_rb" double precision, "foreign_tuition" double precision, "foreign_rb" double precision, "tuition_rb_comments" character varying(254), "evidence" smallint, "testscores" integer, "appfee" integer, "essay" integer, "letters" integer, "interview" integer, "admisothr" integer, "testscoresc" character varying(50), "appfeec" character varying(100), "lettersc" integer, "admiss_other" character varying(50), "cert2000" smallint, "assoc2000" smallint, "ba2000" smallint, "ma2000" smallint, "doc2000" smallint, "remed" smallint, "comacc" integer, "comacc_other" character varying(50), "percent_sign" integer, "percent_cued" integer, "percent_oral" integer, "percent_db" integer, "commacc_often" integer, "tutoring" integer, "tutoring_who" integer, "notetaking" integer, "notetaking_who" integer, "vocservices" integer, "vocservices_who" integer, "perscouns" integer, "perscouns_who" integer, "placement" integer, "placement_who" integer, "deaforg" integer, "speechtherp" integer, "slclassdeaf" integer, "slclasshearing" integer, "slclassteachers" integer, "inservice" integer, "inservice_who" integer, "c_name" character varying(50), "c_title" character varying(50), "c_address_1" character varying(50), "c_address_2" character varying(50), "c_city" character varying(50), "c_state" character varying(2), "c_zip" character varying(10), "c_phone_nmbr_1" character varying(10), "c_phone_ext_1" character varying(6), "c_phone_type_1" smallint, "c_phone_nmbr_2" character varying(10), "c_phone_ext_2" character varying(6), "c_phone_type_2" smallint, "c_e_mail" character varying(80), "sort_by" smallint, Constraint "main_pkey" Primary Key ("id") ); revoke all on "main" from public; grant select on "main" to "apache";
------------------------------------------------------------------------- -- NAME: contacts.sql -- AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> -- WHERE: Gallaudet Research Institute, Washington, DC 20002 -- LASTMOD: 2001.08.01 -- PURPOSE: This table provides details from the College and Career -- Guide, 11th Edition. It contains contact information -- from a follow-up form designed to correct an ambiguity in -- the original form. (See table "main".) -- USAGE: select * from contacts where ...; -- DISCLAIMER: This started life as someone else's Microsoft Access (yeuch!) -- database, and isn't exactly the design I have chosen, but -- I'm stuck with it. -- -- Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ------------------------------------------------------------------------- create table "contacts" ( "id" integer NOT NULL, "email_from" character varying(50), "institution" character varying(60), "a_name" character varying(50), "a_title_position" character varying(200), "a_address_1" character varying(50), "a_address_2" character varying(50), "a_city" character varying(50), "a_state" character varying(2), "a_zip" character varying(10), "a_phone_nmbr_1" character varying(10), "a_phone_ext_1" character varying(6), "a_phone_type_1" smallint, "a_fax" character varying(10), "a_e_mail" character varying(80), "a_www_address" character varying(100), "same_as_above" smallint, "d_name" character varying(50), "d_title_position" character varying(200), "d_address_1" character varying(50), "d_address_2" character varying(50), "d_city" character varying(50), "d_state" character varying(2), "d_zip" character varying(10), "d_phone_nmbr_1" character varying(10), "d_phone_ext_1" character varying(6), "d_phone_type_1" smallint, "d_fax" character varying(10), "d_e_mail" character varying(80), "d_www_address" character varying(100), "comments" text, "responded" smallint, Constraint "contacts_pkey" Primary Key ("id") ); revoke all on "contacts" from public; grant select on "contacts" to "apache";
------------------------------------------------------------------------- -- NAME: states.sql -- AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> -- WHERE: Gallaudet Research Institute, Washington, DC 20002 -- LASTMOD: 2001.08.01 -- PURPOSE: This table provides details from the College and Career -- Guide, 11th Edition. It contains state names and state -- abbreviations. It also contains a number representing the -- states sorted in alphabetical order. -- USAGE: select * from states where ...; -- -- Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ------------------------------------------------------------------------- create table "states" ( "stabbr" character(2) NOT NULL, "stname" character varying(20), "stnumber" smallint, Constraint "states_pkey" Primary Key ("stabbr") ); revoke all on "states" from public; grant select on "states" to "apache";
------------------------------------------------------------------------- -- NAME: majors.sql -- AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> -- WHERE: Gallaudet Research Institute, Washington, DC 20002 -- LASTMOD: 2001.08.01 -- PURPOSE: This table provides details from the College and Career -- Guide, 11th Edition. It contains a list of majors offered -- and a number which corresponds to the majors from the main -- table. (See table "main".) -- USAGE: select * from majors where ...; -- -- Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ------------------------------------------------------------------------- create table "majors" ( "order" smallint NOT NULL, "major_name" character varying(53), Constraint "majors_pkey" Primary Key ("order") ); revoke all on "majors" from public; grant select on "majors" to "apache";
######################################################################### # NAME: Row.py # AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> # WHERE: Gallaudet Research Institute, Washington, DC 20002 # LASTMOD: 2001.08.01 # PURPOSE: This module is part of the College and Career Guide, 11th Edition # search engine. It defines two classes, which are really just # conveniences for the PostgreSQL tables "contacts" and "main". # This was also used to generate a PDF document using the Lout # document layout system. Lout required that special characters # be escaped with quotes. Hence the need for the regular expression # calls. # USAGE: import Row # ... # instance = Form(row,"{html | lout}") # instance = Contact(row,"{html | lout}") # # Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ######################################################################### import types # Data types import re # Regular Expression stuff (regex) quotable = re.compile(r'([/|&{}#@^~\\]+)') class Contact: def __init__(self,row,format): if format == "lout": for col in range(len(row)): if type(row[col]) == types.StringType: row[col] = quotable.sub(r'"\1"',row[col]) self.id = row[0] self.email_from = row[1] self.institution = row[2] self.a_name = row[3] self.a_title_position = row[4] self.a_address_1 = row[5] self.a_address_2 = row[6] self.a_city = row[7] self.a_state = row[8] self.a_zip = row[9] self.a_phone_nmbr_1 = row[10] if type(row[10]) == types.StringType: if len(row[10]) == 10: self.a_phone_nmbr_1 = "("+row[10][:3]+") "+row[10][3:6]+"-"+row[10][6:] self.a_phone_ext_1 = row[11] self.a_phone_type_1 = row[12] self.a_fax = row[13] if type(row[13]) == types.StringType: if len(row[13]) == 10: self.a_fax = "("+row[13][:3]+") "+row[13][3:6]+"-"+row[13][6:] self.a_e_mail = row[14] self.a_www_address = row[15] self.same_as_above = row[16] self.d_name = row[17] self.d_title_position = row[18] self.d_address_1 = row[19] self.d_address_2 = row[20] self.d_city = row[21] self.d_state = row[22] self.d_zip = row[23] self.d_phone_nmbr_1 = row[24] if type(row[24]) == types.StringType: if len(row[24]) == 10: self.d_phone_nmbr_1 = "("+row[24][:3]+") "+row[24][3:6]+"-"+row[24][6:] self.d_phone_ext_1 = row[25] self.d_phone_type_1 = row[26] self.d_fax = row[27] if type(row[27]) == types.StringType: if len(row[27]) == 10: self.d_fax = "("+row[27][:3]+") "+row[27][3:6]+"-"+row[27][6:] self.d_e_mail = row[28] self.d_www_address = row[29] self.comments = row[30] self.responded = row[31] class Form: def __init__(self,row,format): if format == "lout": for col in range(len(row)): if type(row[col]) == types.StringType: row[col] = quotable.sub(r'"\1"',row[col]) self.Entered = row[0] self.id = row[1] self.comments = row[2] self.name = row[3] self.title = row[4] self.department = row[5] self.institution = row[6] self.address_1 = row[7] self.address_2 = row[8] self.city = row[9] self.state = row[10] self.zip = row[11] self.entry_detail = row[12] self.inbook10 = row[13] self.enroll_deaf = row[14] self.fulltime_ugdeaf = row[15] self.parttime_ugdeaf = row[16] self.fulltime_gdeaf = row[17] self.parttime_gdeaf = row[18] self.Deaf_enrc = row[19] self.primary_support = row[20] self.deaf_program = row[21] self.year_estab = row[22] self.admin_50pct = row[23] self.part_progr = row[24] self.name_of_office = row[25] self.program_director = row[26] self.phone_nmbr_1 = row[27] if type(row[27]) == types.StringType: if len(row[27]) == 10: self.phone_nmbr_1 = "("+row[27][:3]+") "+row[27][3:6]+"-"+row[27][6:] self.phone_ext_1 = row[28] self.phone_type_1 = row[29] self.phone_nmbr_2 = row[30] if type(row[30]) == types.StringType: if len(row[30]) == 10: self.phone_nmbr_2 = "("+row[30][:3]+") "+row[30][3:6]+"-"+row[30][6:] self.phone_ext_2 = row[31] self.phone_type_2 = row[32] self.e_mail = row[33] self.inst_web = row[34] self.inst_type = row[35] self.inst_gov = row[36] self.inst_govc = row[37] self.accred = row[38] self.campus = row[39] self.campusc = row[40] self.lart2 = row[41] self.lart4 = row[42] self.gradp = row[43] self.tech2 = row[44] self.tech4 = row[45] self.othpg = row[46] self.voctrn = row[47] self.othpgc = row[48] self.maj_01 = row[49] self.maj_02 = row[50] self.maj_03 = row[51] self.maj_04 = row[52] self.maj_05 = row[53] self.maj_06 = row[54] self.maj_07 = row[55] self.maj_08 = row[56] self.maj_09 = row[57] self.maj_10 = row[58] self.maj_11 = row[59] self.maj_12 = row[60] self.maj_13 = row[61] self.maj_14 = row[62] self.maj_15 = row[63] self.maj_16 = row[64] self.maj_17 = row[65] self.maj_18 = row[66] self.maj_19 = row[67] self.maj_20 = row[68] self.maj_21 = row[69] self.maj_22 = row[70] self.maj_23 = row[71] self.maj_24 = row[72] self.maj_25 = row[73] self.maj_26 = row[74] self.maj_27 = row[75] self.maj_28 = row[76] self.maj_29 = row[77] self.maj_30 = row[78] self.maj_31 = row[79] self.maj_32 = row[80] self.maj_33 = row[81] self.maj_34 = row[82] self.maj_35 = row[83] self.maj_36 = row[84] self.maj_37 = row[85] self.maj_38 = row[86] self.maj_39 = row[87] self.maj_40 = row[88] self.UGftenr = row[89] self.UGptenr = row[90] self.Gftenr = row[91] self.Gptenr = row[92] self.enrc = row[93] self.dorms = row[94] if row[95] != None: self.local_tuition = int(row[95] + 0.5) else: self.local_tuition = row[95] if row[96] != None: self.local_rb = int(row[96] + 0.5) else: self.local_rb = row[96] if row[97] != None: self.state_tuition = int(row[97] + 0.5) else: self.state_tuition = row[97] if row[98] != None: self.state_rb = int(row[98] + 0.5) else: self.state_rb = row[98] if row[99] != None: self.other_tuition = int(row[99] + 0.5) else: self.other_tuition = row[99] if row[100] != None: self.other_rb = int(row[100] + 0.5) else: self.other_rb = row[100] if row[101] != None: self.foreign_tuition = int(row[101] + 0.5) else: self.foreign_tuition = row[101] if row[102] != None: self.foreign_rb = int(row[102] + 0.5) else: self.foreign_rb = row[102] self.tuition_rb_comments = row[103] self.evidence = row[104] self.testscores = row[105] self.appfee = row[106] self.essay = row[107] self.letters = row[108] self.interview = row[109] self.admisothr = row[110] self.testscoresc = row[111] self.appfeec = row[112] self.lettersc = row[113] self.admiss_other = row[114] self.cert2000 = row[115] self.assoc2000 = row[116] self.ba2000 = row[117] self.ma2000 = row[118] self.doc2000 = row[119] self.remed = row[120] self.comacc = row[121] self.comacc_other = row[122] self.percent_sign = row[123] self.percent_cued = row[124] self.percent_oral = row[125] self.percent_db = row[126] self.commacc_often = row[127] self.tutoring = row[128] self.tutoring_who = row[129] self.notetaking = row[130] self.notetaking_who = row[131] self.vocservices = row[132] self.vocservices_who = row[133] self.perscouns = row[134] self.perscouns_who = row[135] self.placement = row[136] self.placement_who = row[137] self.deaforg = row[138] self.speechtherp = row[139] self.slclassdeaf = row[140] self.slclasshearing = row[141] self.slclassteachers = row[142] self.inservice = row[143] self.inservice_who = row[144] self.c_name = row[145] self.c_title = row[146] self.c_address_1 = row[147] self.c_address_2 = row[148] self.c_city = row[149] self.c_state = row[150] self.c_zip = row[151] self.c_phone_nmbr_1 = row[152] self.c_phone_ext_1 = row[153] self.c_phone_type_1 = row[154] self.c_phone_nmbr_2 = row[155] self.c_phone_ext_2 = row[156] self.c_phone_type_2 = row[157] self.c_e_mail = row[158] class Major: def __init__(self,row,format): if format == "lout": for col in range(len(row)): if type(row[col]) == types.StringType: row[col] = quotable.sub(r'"\1"',row[col]) self.code = row[0] self.name = row[1]
######################################################################### # NAME: money.py # AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> # WHERE: Gallaudet Research Institute, Washington, DC 20002 # LASTMOD: 2001.08.01 # PURPOSE: This module is part of the College and Career Guide, 11th Edition # search engine. It adds '$' and ',' to money amounts smaller than # 1 million. Some day, I'll make it more general, but don't hold # your breath. # USAGE: import * from money # ... # printable = money(floating) # # Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ######################################################################### def money(dollars): build = "%d" % (dollars) if (dollars > 999): comma = len(build) - 3 format = "$%%.%ds,%%.3s" % (comma) obuf = format % (build[:comma],build[comma:]) else: obuf = "$%s" % (build) return obuf
#!/usr/bin/env python ######################################################################### # NAME: schools.py # AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> # WHERE: Gallaudet Research Institute, Washington, DC 20002 # LASTMOD: 2001.08.07 # PURPOSE: This generates a web page with a search form at the top, # an image map of the U.S. and a list of schools, sorted by # state at the bottom. # USAGE: http://host/schools.cgi # # Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ######################################################################### # NOTE: The PostgreSQL-Python package requires the egenix-mx-base package, # (providing "mx" extensions to Python) The RPM installs into the # wrong directory, forcing us to use the sys.path.insert() below. import sys sys.path.insert(0,"/usr/lib/python1.5/site-packages") import pgdb import os from time import * from string import * # Get the current time and massage it a few times. today = localtime(time()) # (yyyy,mm,dd,hh,mm,ss,wd,jd,DST) yyyy,mm,dd,hh,nn,ss = today[0],today[1],today[2],today[3],today[4],today[5] next_year = localtime(mktime((yyyy+1,)+(today[1:]))) right_now = strftime("%a %b %d %H:%M:%S %%s %Y",today) % (tzname[today[8]]) created = strftime("%a. %d %b %Y %H:%M:%S %%s",today) % (tzname[today[8]]) expires = strftime("expires=%A, %d-%b-%Y 23:59:59 %%s",next_year) % (tzname[today[8]]) # Query templates get_states = "select stabbr,stname" get_states = get_states+" from states" get_states = get_states+" where stabbr !='SK'" get_states = get_states+" order by stname;" get_schools = "select institution" get_schools = get_schools+" from main" get_schools = get_schools+" where enroll_deaf = 1" get_schools = get_schools+" and state = '%s'" get_schools = get_schools+" order by institution;" get_majors = "select major_name" get_majors = get_majors+" from majors" get_majors = get_majors+" order by major_name;" # Connect to (i.e. open) the ccg11 database and create # some cursors. ccg11 = pgdb.connect("localhost:ccg11") states = ccg11.cursor() schools = ccg11.cursor() majors = ccg11.cursor() print "Content-Type: text/html\n" # HTML Header print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"""" print """ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n""" print """<html>""" print """<head>""" print """<link rel="stylesheet" type="text/css" href="CSS/prototype.css" />""" print """<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />""" print """<meta http-equiv="Reply-To" content="kjcole@gri.gallaudet.edu" />""" print """<meta http-equiv="Resource-Type" content="document" />""" print """<meta http-equiv="Distribution" content="global" />""" print """<meta http-equiv="Generator" content="Linux, PostgreSQL, and gcc" />""" print """<meta http-equiv="Copyright" content="Gallaudet Research Institute, 2001" />""" print """<meta name="generator" content="Linux, PostgreSQL, and Python" />""" print """<meta name="author" content="Kevin Cole, Systems Guru" />""" print """<meta name="creation_date" content="Thu. 04 Dec 1994 09:16:25 GMT" />""" print """<meta name="keywords" content="college career deaf hearing-impaired" />""" print """<meta name="description" content="Program descriptions" />""" print """<title>College and Career Guide - Program Descriptions</title>""" print """</head>\n" # HTML Body print """<body>\n""" print """<table width="640"""" print """ border="1" cellspacing="0" cellpadding="0" height="315">\n""" print """<tr>""" print """<td class="frills" colspan=2 width="628"><map name="FPMap0">""" print """<area href="/ccg/index.html" shape="rect" coords="44, 0, 341, 35">""" print """<area href="/ccg/index.html" shape="rect" coords="439, 4, 490, 31">""" print """<area href="/cgi-bin/schools.cgi" shape="rect" coords="490, 4, 627, 31"></map>""" print """<img src="/ccg/images/ccgbarsmall.gif" alt="[Toolbar]"""" print """ border="0" usemap="#FPMap0" width="640" height="36"></td>""" print """</tr>""" print """<tr><td class="frills" width="43" valign="top"> </td>""" print """<td width="480">""" print """<img src="/ccg/images/descriptions.gif"""" print """ border="0" alt="[Program descriptions]" width="332" height="48">""" print """<br />""" print """<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>INSTRUCTIONS:</b></p>""" print """<p>Use either the SEARCH FORM or the LOCATOR MAP below to obtain details on""" print """specific programs.</font></p>\n""" print """<p><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><b>SEARCH FORM</b></p>""" print """<p>Fill in as many of the following fields as you wish. Then click the""" print """SUBMIT button. <i>Note:</i> You can enter partial names for the institution.""" print """For example, entering "<b>east</b>" will find any schools with "east"""" print """anywhere in their names (like""" print """<b>Eastern Kentucky University</b> or """ print """<b>Northeast University</b> or""" print """<b>Indiana University Southeast</b>).</font></p>\n""" print """<blockquote><p><font face="Verdana, Arial, Helvetica, sans-serif" size="2">""" print """<form action="/cgi-bin/query.cgi" method="post">""" print """<input type="hidden" name="match" value="vague">""" print """<b>School:</b> <input type="text" name="institution" size="40"><br />""" print """<b>State:</b> <select name="state">""" print """\t\t<option selected>*** Any state ***""" states.execute(get_states) for state in states.fetchall(): print "\t\t<option>%s" % (state[0]) print "\t </select><br />" print "<b>Major:</b> <select name=\"major\">" print "\t\t<option selected>*** Any major ***" majors.execute(get_majors) for major in majors.fetchall(): print "\t\t<option>%s" % (replace(major[0],"&","&")) print "\t </select><br />" print "<input type=\"submit\" value=\"Search\"> <input type=\"reset\" value=\"Clear\"><br />" print "</form>" print "</font></p></blockquote>\n" print "<hr noshade />\n" print "<p><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\"><b>LOCATOR MAP</b></p>" print "<p>Click a state on the map below to see a list of all programs within that state.</font></p>" print "<script type=\"text/javascript\" language=\"javascript\" src=\"/scripts/map-usa.js\"></script>\n" print "<hr noshade />\n" print "<p><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\"><b>Programs listed by state</b></font></p>" states.execute(get_states) for state in states.fetchall(): schools.execute(get_schools % (state[0])) print "<div class=\"state\"><a name=\"%s\"><b>%s</b></a></div>" % (state[0],state[1]) print "<div class=\"schools\">" if schools.rowcount > 0: for school in schools.fetchall(): print "<a href=\"http://gri.gallaudet.edu/cgi-bin/school-fetch?%s\">" % (replace(school[0]," ","+")) print "%s</a><br />" % (school[0]) else: print "No institutions with programs reported.<br />" print "<br /></div>" print "</td></tr>\n" print "<tr>" print "<td class=\"frills\" width=\"655\" height=\"57\" valign=\"middle\" colspan=\"2\">" print "<div align=\"center\">" print "<font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">" print "<a href=\"http://gspp.gallaudet.edu\">Graduate School and Professional Programs</a><br />" print "<a href=\"http://www.gallaudet.edu\">Gallaudet University</a><br />" print "800 Florida Avenue, NE<br />" print "Washington, DC 20002<br />" print "</font>" print "</div>" print "<p align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">Website" print "designed by Susan J. King and Kevin J. Cole, GSPP/TIS<br />" #print "<script type=\"text/javascript\"" #print " language=\"javascript\"" #print " src=\"/scripts/LastMod.js\">" #print "</script></td>" print "Page generated on: %s</font></p></td>" % (created) print " </tr>" print "</table>" print "</body>" print "</html>"
#!/usr/bin/env python ######################################################################### # NAME: query.py # AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> # WHERE: Gallaudet Research Institute, Washington, DC 20002 # LASTMOD: 2001.08.01 # PURPOSE: This program provides details from the College and Career # Guide, 11th Edition. It accepts data from a web form, and # uses it to build a PostgreSQL database query. If the query # returns more than one row, the program will generate a second # web form that allows the end-user to select a single row # (school). Once a single row has been selected, the program # generates a page with the details for that particular school. # The page layout is based on the layout produced by publish.py, # which generated a Lout source file. # USAGE: <form action="/cgi-bin/query.cgi" method="post"> # <input type="hidden" name="match" value="{vague | exact}"> # <input type="text" name="institution"> # <input type=??? name="state"> # <input type=??? name="major"> # ... # </form> # # Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ######################################################################### # # NOTE: The PostgreSQL-Python package requires the egenix-mx-base package, # (providing "mx" extensions to Python) The RPM installs into the # wrong directory, forcing us to use the sys.path.insert() below. # from sys import * # Which OS are we using? path.insert(0,"/usr/lib/python1.5/site-packages") import cgi # Common Gateway Interface import urllib # URL decoder/encoder import os # Operating system functions import os.path # Ditto import pgdb # PostgreSQL interface from stat import * # Get file stats (size, etc) from time import * # Monkey with dates from string import * # Monkey with strings from Row import * # Database row field definitions from money import * # Adds "$" and "," to money amounts # What time is it? It's Howdy-Doody Time! (Get the current time in # several usable flavors.) Note the TimeZone name addition. today = localtime(time()) # (yyyy,mm,dd,hh,mm,ss,wd,jd,DST) yyyy,mm,dd,hh,nn,ss = today[0],today[1],today[2],today[3],today[4],today[5] right_now = strftime("%a %b %d %H:%M:%S %%s %Y",today) % (tzname[today[8]]) created = strftime("%a. %d %b %Y %H:%M:%S %%s",today) % (tzname[today[8]]) next_year = localtime(mktime((yyyy+1,)+(today[1:]))) expires = strftime("expires=%A, %d-%b-%Y 23:59:59 %%s",next_year) % (tzname[today[8]]) def toolbar(): print "<table width=\"640\"" print " border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n" print "<tr>" print "<td class=\"frills\" colspan=\"2\" width=\"640\"><map name=\"FPMap0\">" print "<area href=\"/ccg/index.html\" shape=\"rect\" coords=\"44, 0, 341, 35\">" print "<area href=\"/ccg/index.html\" shape=\"rect\" coords=\"439, 4, 490, 31\">" print "<area href=\"/cgi-bin/schools.cgi\" shape=\"rect\" coords=\"490, 4, 627, 31\"></map>" print "<img src=\"/ccg/images/ccgbarsmall.gif\" alt=\"[Toolbar]\"" print " border=\"0\" usemap=\"#FPMap0\" width=\"640\" height=\"36\"></td>" print "</tr>" print "</table>" def footer(): print "<table width=\"640\"" print " border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n" print " <tr>" print " <td class=\"frills\" colspan=\"2\" width=\"640\" height=\"57\" valign=\"middle\">" print " <div align=\"center\">" print " <font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\"><a href=\"http://gspp.gallaudet.edu\"><br />" print " Graduate School and Professional Programs</a><br />" print " <a href=\"http://www.gallaudet.edu\">Gallaudet University</a><br />" print " 800 Florida Avenue, NE<br />" print " Washington, DC 20002<br />" print " </font>" print " </div>" print " <p align=\"center\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"2\">Website" print " designed by Susan J. King and Kevin J. Cole, GSPP/TIS<br />" print " Page generated on: %s</font></p></td>" % (created) print " </tr>" print "</table>" # Connect to (i.e. open) the ccg11 database, and establish 3 "cursors" for it. ccg11 = pgdb.connect("localhost:ccg11") schools = ccg11.cursor() contacts = ccg11.cursor() majors = ccg11.cursor() # Make a majors dictionary. diplomas["major_name"] = "major_##". diplomas = {} # Create an empty dictionary majors = ccg11.cursor() majors.execute("select * from majors;") for major in majors.fetchall(): diplomas[major[1]] = major[0] names = diplomas.keys() names.sort() match = "vague" # Initialize query parameters institution = "" # Ditto state = "*** Any state ***" # Ditto major = "*** Any major ***" # Ditto criteria = "" # Ditto # Get the web form data queryForm = cgi.FieldStorage() if queryForm.has_key("match"): match = queryForm["match"].value if queryForm.has_key("institution"): institution = queryForm["institution"].value if queryForm.has_key("state"): state = queryForm["state"].value if queryForm.has_key("major"): major = queryForm["major"].value # Escape the silly apostrophe in Kapi'olana or whatever that school is. institution = replace(institution,"'","''") # Chop institution after the semi-colon (If we've entered this from # a generated list of schools, eliminate the state and possibly the # major appended to the end of the institution.) if match == "exact": criteria = criteria+"institution = '%s'" % (split(institution,";")[0]) else: if institution != "": criteria = criteria+"institution ~* '.*%s.*'" % (split(institution,";")[0]) if state != "*** Any state ***": if len(criteria) > 0: criteria = criteria+" and " criteria = criteria+"state = '%s'" % (state) if major != "*** Any major ***": if len(criteria) > 0: criteria = criteria+" and " criteria = criteria+"maj_%2.2d > 0" % (diplomas[major]) # Build a cookie for return visitors... We MIGHT change this # to build the cookie based on the final single page rather than # basing it on the initial query. #cookie = "PatronInfo=" #cookie = cookie+("institution:%s" % (urllib.quote(institution))) #cookie = cookie+("&state:%s" % (urllib.quote(state))) #cookie = cookie+";" #print "Set-Cookie: %s path=/ %s" % ((cookie,expires)) get_school = "select *" get_school = get_school+" from main" get_school = get_school+" where enroll_deaf = 1" get_school = get_school+" and state != 'SK'" get_school = get_school+" and "+criteria get_school = get_school+" order by institution;" print "Content-Type: text/html\n" print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"" print " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" print "<html>" print "<head>" print "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/prototype.css\" />" print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" print "<meta http-equiv=\"Reply-To\" content=\"kjcole@gri.gallaudet.edu\" />" print "<meta http-equiv=\"Resource-Type\" content=\"document\" />" print "<meta http-equiv=\"Distribution\" content=\"global\" />" print "<meta http-equiv=\"Generator\" content=\"Linux, PostgreSQL, and Python\" />" print "<meta http-equiv=\"Copyright\" content=\"Gallaudet Research Institute, 2001\" />" print "<meta name=\"generator\" content=\"Linux, PostgreSQL, and Python\" />" print "<meta name=\"author\" content=\"Kevin Cole, Systems Guru\" />" print "<meta name=\"creation_date\" content=\"%s\" />" % (created) if institution == "" and \ state == "*** Any state ***" and \ major == "*** Any major ***": print "<meta name=\"keywords\" content=\"error no criteria specified\" />" print "<meta name=\"description\" content=\"No seach criteria provided\" />" print "<title>No search criteria provided</title>" print "</head>\n" print "<body>" toolbar() # Draw Toolbar print "<p>You did not provide any search criteria. You must either fill in" print "some information in the form at the top of the page, or select a" print "school from the list provided at the bottom of the previous page.</p>" print "<form><center><p>" print "<input type=\"button\"" print " onClick=\"location.replace('/cgi-bin/schools.cgi')\"" print " value=\"Back\">" print "</p></center></form>" footer() # Credits print "</body></html>" else: schools.execute(get_school) if schools.rowcount == 0: print "<meta name=\"keywords\" content=\"error no search results\" />" print "<meta name=\"description\" content=\"No match for institution %s, state %s\" />" % (institution,state) print "<title>Query results</title>" print "</head>\n" print "<body>" toolbar() # Draw Toolbar print "<p>No schools matched your search criteria.</p>" print "<form><center><p>" print "<input type=\"button\"" print " onClick=\"location.replace('/cgi-bin/schools.cgi')\"" print " value=\"Back\">" print "</p></center></form>" footer() # Credits print "</body></html>" elif schools.rowcount > 1: print "<meta name=\"keywords\" content=\"deaf college university search results\" />" print "<meta name=\"description\" content=\"Results of search for %s %s\" />" % (institution,state) print "<title>Query results</title>" print "</head>\n" print "<body>" toolbar() # Draw Toolbar print "<p>%s schools matched your criteria.</p>" % (schools.rowcount) if major != "*** Any major ***": print "<center><p><b>%s</b></p></center>" % (major) print "<p><b>Note:</b> The level of training offered at an institution" print "is indicated by the letters in parenthesis: <b>C</b>=Certificate/Diploma;" print "<b>A</b>=Associate's degree; <b>B</b>=Bachelor's degree; <b>M</b>=Master's degree;" print "and <b>D</b>=Doctorate degree.</p>" print "<hr noshade />" print "<form action=\"/cgi-bin/query.cgi\" method=\"post\">" print "<p>Choose a school from the menu below:</p>" print "<input type=\"hidden\" name=\"match\" value=\"exact\">" print "<input type=\"hidden\" name=\"state\" value=\"*** Any state ***\">" print "<input type=\"hidden\" name=\"major\" value=\"*** Any major ***\">" print "<blockquote><p><select name=\"institution\">" for school in schools.fetchall(): s = Form(school,"html") if major != "*** Any major ***": flags = "%5.5d" % (school[diplomas[major]+48]) # Binar-ize, sort of offered = "" available = ("C","A","B","M","D") for level in range(5): if flags[level:level+1] == "1": if len(offered) > 0: offered = offered+", " offered = offered+available[level] print "<option>%s; %s (%s)" % (s.institution,s.state,offered) else: print "<option>%s; %s" % (s.institution,s.state) print "</select>" print "<br />" print "<input type=\"submit\" value=\"Show school\">" print "<input type=\"button\" value=\"Cancel\"" print " onClick=\"location.replace('/cgi-bin/schools.cgi')\">" print "</p></blockquote>" print "</form>" print "<hr noshade />" footer() # Credits print "</body></html>" else: for school in schools.fetchall(): s = Form(school,"html") get_contact = "select * from contacts where id = %s" % (s.id) contacts.execute(get_contact) if contacts.rowcount == 1: for contact in contacts.fetchall(): c = Contact(contact,"html") responded = c.responded else: responded = 0 print "<meta name=\"keywords\" content=\"%s %s %s\" />" % (s.institution,s.city,s.state) print "<meta name=\"description\" content=\"Program description for %s\" />" % (s.institution) print "<title>%s</title>" % (s.institution) print "</head>\n" print "<body>" toolbar() # Draw Toolbar print "<div>" print "<span class=\"school\"><a href=\"%s\">%s</a></span><br />" % (s.inst_web,s.institution) if s.deaf_program != None: print "<span class=\"progrm\">%s</span><br />" % (s.deaf_program) print "<span class=\"city\">%s, %s</span><br />" % (s.city, s.state) education = "" if s.lart2 == 1 or s.lart4 == 1: education = education+"Liberal Arts, " if s.tech2 == 1 or s.tech4 == 1: education = education+"Technical, " if s.gradp == 1: education = education+"Graduate, " if s.voctrn == 1: education = education+"\"Vocational/Technical\", " if s.othpgc != None: education = education+"Other, " print "<span class=\"degree\"><i>%s</i></span><br />" % (education[:-2]) if s.program_director != None: print "Program administrator: %s<br />" % (s.program_director) if s.inst_web != None: print "URL: <a href=\"%s\">%s</a>" % (s.inst_web,s.inst_web) print "</div>\n" print "<hr noshade />\n" # print "<multicol cols=\"2\" gutter=\"5\">\n" print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"" print " summary=\"Two columns of feature details\">" print "<tr valign=\"top\"><td>" if (responded == 1) and (c.same_as_above == 1): print "<div class=\"feature\"><b>PROGRAM & ADMISSIONS INFORMATION</b></div>" print "<div class=\"detail\">" if c.a_name != None: print "%s<br />" % (c.a_name) if c.a_title_position != None: print "%s<br />" % (c.a_title_position) if c.a_address_1 != None: print "%s<br />" % (c.a_address_1) if c.a_address_2 != None: print "%s<br />" % (c.a_address_2) csz = "" if c.a_city != None: csz = csz + "%s" % (c.a_city) if c.a_state != None: csz = csz + ", %s" % (c.a_state) if c.a_zip != None: csz = csz + " %s" % (c.a_zip) if len(csz) > 0: print "%s<br />" % (csz) phone = "" if c.a_phone_nmbr_1 != None: phone = phone + "Telephone: %s" % (c.a_phone_nmbr_1) if c.a_phone_ext_1 != None: phone = phone + " %s" % (c.a_phone_ext_1) if c.a_phone_type_1 == 1: phone = phone + " (Voice)" if c.a_phone_type_1 == 2: phone = phone + " (TTY)" if c.a_phone_type_1 == 3: phone = phone + " (Voice & TTY)" if len(phone) > 0: print "%s<br />" % (phone) if c.a_fax != None: print "FAX: %s<br />" % (c.a_fax) if c.a_e_mail != None: print "E-mail: <a href=\"mailto:%s\">%s</a><br />" % (c.a_e_mail,c.a_e_mail) print "<br /></div>\n" else: if (responded == 1) and (c.d_address_1 != None): print "<div class=\"feature\"><b>PROGRAM INFORMATION</b></div>" print "<div class=\"detail\">" if c.d_name != None: print "%s<br />" % (c.d_name) if c.d_title_position != None: print "%s<br />" % (c.d_title_position) if c.d_address_1 != None: print "%s<br />" % (c.d_address_1) if c.d_address_2 != None: print "%s<br />" % (c.d_address_2) csz = "" if c.d_city != None: csz = csz + "%s" % (c.d_city) if c.d_state != None: csz = csz + ", %s" % (c.d_state) if c.d_zip != None: csz = csz + " %s" % (c.d_zip) if len(csz) > 0: print "%s<br />" % (csz) phone = "" if c.d_phone_nmbr_1 != None: phone = phone + "Telephone: %s" % (c.d_phone_nmbr_1) if c.d_phone_ext_1 != None: phone = phone + " %s" % (c.d_phone_ext_1) if c.d_phone_type_1 == 1: phone = phone + " (Voice)" if c.d_phone_type_1 == 2: phone = phone + " (TTY)" if c.d_phone_type_1 == 3: phone = phone + " (Voice & TTY)" if len(phone) > 0: print "%s<br />" % (phone) if c.d_fax != None: print "FAX: %s<br />" % (c.d_fax) if c.d_e_mail != None: print "E-mail: <a href=\"mailto:%s\">%s</a><br />" % (c.d_e_mail,c.d_e_mail) print "<br /></div>\n" if (responded == 1) and (c.a_address_1 != None): print "<div class=\"feature\"><b>ADMISSIONS INFORMATION</b></div>" print "<div class=\"detail\">" if c.a_name != None: print "%s<br />" % (c.a_name) if c.a_title_position != None: print "%s<br />" % (c.a_title_position) if c.a_address_1 != None: print "%s<br />" % (c.a_address_1) if c.a_address_2 != None: print "%s<br />" % (c.a_address_2) csz = "" if c.a_city != None: csz = csz + "%s" % (c.a_city) if c.a_state != None: csz = csz + ", %s" % (c.a_state) if c.a_zip != None: csz = csz + " %s" % (c.a_zip) if len(csz) > 0: print "%s<br />" % (csz) phone = "" if c.a_phone_nmbr_1 != None: phone = phone + "Telephone: %s" % (c.a_phone_nmbr_1) if c.a_phone_ext_1 != None: phone = phone + " %s" % (c.a_phone_ext_1) if c.a_phone_type_1 == 1: phone = phone + " (Voice)" if c.a_phone_type_1 == 2: phone = phone + " (TTY)" if c.a_phone_type_1 == 3: phone = phone + " (Voice & TTY)" if len(phone) > 0: print "%s<br />" % (phone) if c.a_fax != None: print "FAX: %s<br />" % (c.a_fax) if c.a_e_mail != None: print "E-mail: <a href=\"mailto:%s\">%s</a><br />" % (c.a_e_mail,c.a_e_mail) print "<br /></div>\n" if (responded != 1): print "<div class=\"feature\"><b>PROGRAM INFORMATION</b></div>" print "<div class=\"detail\">" if s.name != None: print "%s<br />" % (s.name) if s.title != None: print "%s<br />" % (s.title) if s.department != None: print "%s<br />" % (s.department) if s.address_1 != None: print "%s<br />" % (s.address_1) if s.address_2 != None: print "%s<br />" % (s.address_2) csz = "" if s.city != None: csz = csz + "%s" % (s.city) if s.state != None: csz = csz + ", %s" % (s.state) if s.zip != None: csz = csz + " %s" % (s.zip) if len(csz) > 0: print "%s<br />" % (csz) phone = "" if s.phone_nmbr_1 != None: phone = phone + "Telephone: %s" % (s.phone_nmbr_1) if s.phone_ext_1 != None: phone = phone + " %s" % (s.phone_ext_1) if s.phone_type_1 == 1: phone = phone + " (Voice)" if s.phone_type_1 == 2: phone = phone + " (TTY)" if s.phone_type_1 == 3: phone = phone + " (Voice & TTY)" if len(phone) > 0: print "%s<br />" % (phone) if s.e_mail != None: print "E-mail: <a href=\"mailto:%s\">%s</a><br />" % (s.e_mail,s.e_mail) print "<br /></div>\n" undergraduates = 0 # FALSE graduates = 0 # FALSE print "<div class=\"feature\"><b>ENROLLMENT, FALL 2000 TERM</b></div>" print "<div class=\"detail\">" if (s.UGftenr != None and s.UGftenr != 0) or \ (s.UGptenr != None and s.UGptenr != 0) or \ (s.fulltime_ugdeaf != None and s.fulltime_ugdeaf != 0) or \ (s.parttime_ugdeaf != None and s.parttime_ugdeaf != 0): undergraduates = 1 # TRUE if (s.Gftenr != None and s.Gftenr != 0) or \ (s.Gptenr != None and s.Gptenr != 0) or \ (s.fulltime_gdeaf != None and s.fulltime_gdeaf != 0) or \ (s.parttime_gdeaf != None and s.parttime_gdeaf != 0): graduates = 1 # TRUE if (undergraduates == 0) and (graduates == 0): print "Contact the school for information.<br />" else: print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"" print " summary=\"Category of student, followed by number of students in category\">" print "<tr>" print "<td> </td>" print "<td class=\"tabdet\" align=\"center\"><i> All<br /> Students</i></td>" print "<td class=\"tabdet\" align=\"center\"><i>Deaf<br /> Students</i></td>" print "</tr>" if undergraduates == 1: if s.UGftenr == None: s.UGftenr = " " if s.fulltime_ugdeaf == None: s.fulltime_ugdeaf = " " if s.UGptenr == None: s.UGptenr = " " if s.parttime_ugdeaf == None: s.parttime_ugdeaf = " " print "<tr>\n<th align=\"left\">Undergraduate</th>\n</tr>" print "<tr>" print "<td class=\"detail\" align=\"right\">Full-time:</td>" print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.UGftenr) print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.fulltime_ugdeaf) print "</tr>" print "<tr>" print "<td class=\"detail\" align=\"right\">Part-time:</td>" print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.UGptenr) print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.parttime_ugdeaf) print "</tr>" if (s.gradp == 1) and (graduates == 1): if s.Gftenr == None: s.Gftenr = " " if s.fulltime_gdeaf == None: s.fulltime_gdeaf = " " if s.Gptenr == None: s.Gptenr = " " if s.parttime_gdeaf == None: s.parttime_gdeaf = " " print "<tr>\n<th align=\"left\">Graduate</th>\n</tr>" print "<tr>" print "<td class=\"detail\" align=\"right\">Full-time:</td>" print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.Gftenr) print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.fulltime_gdeaf) print "</tr>" print "<tr>" print "<td class=\"detail\" align=\"right\">Part-time:</td>" print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.Gptenr) print "<td class=\"tabdet\" align=\"right\">%s </td>" % (s.parttime_gdeaf) print "</tr>" print "</table>" print "<br /></div>\n" housing = "" print "<div class=\"feature\"><b>SUPERVISED HOUSING</b></div>" print "<div class=\"detail\">" if s.dorms == None: housing = "Not reported" elif s.dorms == 0: housing = "Supervised housing not available" elif s.dorms == 1: housing = "Supervised housing available" print "%s<br />" % (housing) print "<br /></div>\n" loctuit = s.local_tuition sttuit = s.state_tuition osttuit = s.other_tuition fortuit = s.foreign_tuition locrab = s.local_rb strab = s.state_rb ostrab = s.other_rb forrab = s.foreign_rb print "<div class=\"feature\"><b>COSTS, 2000-2001</b><span class=\"super\">¹</span></div>" print "<div class=\"detail\">" if (loctuit == None or loctuit == 0) and (locrab == None or locrab == 0) and \ (sttuit == None or sttuit == 0) and (strab == None or strab == 0) and \ (osttuit == None or osttuit == 0) and (ostrab == None or ostrab == 0) and \ (fortuit == None or fortuit == 0) and (forrab == None or forrab == 0): print "Contact the school for information.<br />" else: print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"" print " summary=\"Residency status, followed by tuition and/or room & board\">" if (s.dorms == 1) and \ ((locrab != None and locrab != 0) or \ (strab != None and strab != 0) or \ (ostrab != None and ostrab != 0) or \ (forrab != None and forrab != 0)): print "<tr>" print "<td> </td>" print "<td class=\"tabdet\" align=\"center\"><i> <br /> Tuition</i></td>" print "<td class=\"tabdet\" align=\"center\"><i> Room &<br />Board</i></td>" print "</tr>" else: print "<tr>" print "<td> </td>" print "<td class=\"tabdet\" align=\"center\"><i> Tuition</i></td>" print "<td> </td>" print "</tr>" locrab = None strab = None ostrab = None forrab = None if (loctuit == sttuit and sttuit == osttuit and osttuit == fortuit and \ locrab == strab and strab == ostrab and ostrab == forrab): if (loctuit != None and loctuit > 0) or \ (locrab != None and locrab > 0): if (loctuit != None and loctuit > 0): tuit = "%s" % (money(loctuit)) else: tuit = " " if (locrab != None and locrab > 0): rab = "%s" % (money(locrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">All Students</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" elif (loctuit == sttuit and sttuit == osttuit and \ locrab == strab and strab == ostrab): if (loctuit != None and loctuit > 0) or \ (locrab != None and locrab > 0): if (loctuit != None and loctuit > 0): tuit = "%s" % (money(loctuit)) else: tuit = " " if (locrab != None and locrab > 0): rab = "%s" % (money(locrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">United States Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if (fortuit != None and fortuit > 0) or \ (forrab != None and forrab > 0): if (fortuit != None and fortuit > 0): tuit = "%s" % (money(fortuit)) else: tuit = " " if (forrab != None and forrab > 0): rab = "%s" % (money(forrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">International Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" elif (loctuit == sttuit and locrab == strab): if (sttuit != None and sttuit > 0) or \ (strab != None and strab > 0): if (sttuit != None and sttuit > 0): tuit = "%s" % (money(sttuit)) else: tuit = " " if (strab != None and strab > 0): rab = "%s" % (money(strab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">State Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if (osttuit != None and osttuit > 0) or \ (ostrab != None and ostrab > 0): if (osttuit != None and osttuit > 0): tuit = "%s" % (money(osttuit)) else: tuit = " " if (ostrab != None and ostrab > 0): rab = "%s" % (money(ostrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">Out-of-State Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if ((fortuit != osttuit) or (forrab != ostrab)): if ((fortuit != None and fortuit > 0) or \ (forrab != None and forrab > 0)): if (fortuit != None and fortuit > 0): tuit = "%s" % (money(fortuit)) else: tuit = " " if (forrab != None and forrab > 0): rab = "%s" % (money(forrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">International Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" else: if (loctuit != None and loctuit > 0) or \ (locrab != None and locrab > 0): if (loctuit != None and loctuit > 0): tuit = "%s" % (money(loctuit)) else: tuit = " " if (locrab != None and locrab > 0): rab = "%s" % (money(locrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">Local Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if (sttuit != None and sttuit > 0) or \ (strab != None and strab > 0): if (sttuit != None and sttuit > 0): tuit = "%s" % (money(sttuit)) else: tuit = " " if (strab != None and strab > 0): rab = "%s" % (money(strab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">State Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if (osttuit != None and osttuit > 0) or \ (ostrab != None and ostrab > 0): if (osttuit != None and osttuit > 0): tuit = "%s" % (money(osttuit)) else: tuit = " " if (ostrab != None and ostrab > 0): rab = "%s" % (money(ostrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">Out-of-State Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" if ((fortuit != osttuit) or (forrab != ostrab)): if (fortuit != None and fortuit > 0) or \ (forrab != None and forrab > 0): if (fortuit != None and fortuit > 0): tuit = "%s" % (money(fortuit)) else: tuit = " " if (forrab != None and forrab > 0): rab = "%s" % (money(forrab)) else: rab = " " print "<tr>" print "<td class=\"tabdet\" align=\"left\">International Residents</td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (tuit) print "<td class=\"tabdet\" align=\"right\">%s</td>" % (rab) print "</tr>" print "</table>" print "<br /></div>\n" if s.evidence != None or \ s.testscores != None or \ s.appfee != None or \ s.essay != None or \ s.letters != None or \ s.interview != None or \ s.admisothr != None: print "<div class=\"feature\"><b>UNDERGRADUATE ADMISSION REQUIREMENTS</b></div>" print "<div class=\"detail\">" if s.evidence == 1: print "<b>·</b> Evidence of high school graduation<br />" if s.testscores == 1: if s.testscoresc != None: print "<b>·</b> Standardized test scores: %s<br />" % (s.testscoresc) else: print "<b>·</b> Standardized test scores<br />" if s.appfee == 1: if s.appfeec != None: print "<b>·</b> Application fee: %s<br />" % (s.appfeec) else: print "<b>·</b> Application fee<br />" if s.essay == 1: print "<b>·</b> Essay or writing sample<br />" if s.letters == 1: if s.lettersc != None: print "<b>·</b> Letter(s) of recommendation: %s<br />" % (s.lettersc) else: print "<b>·</b> Letter(s) of recommendation<br />" if s.interview == 1: print "<b>·</b> Interview<br />" if s.admisothr == 1 and \ s.admiss_other != None: print "<b>·</b> %s<br />" % (s.admiss_other) print "<br /></div>\n" inst_type = "" if s.campus == 1: inst_type = "Urban" elif s.campus == 2: inst_type = "Suburban" elif s.campus == 3: inst_type = "Rural" if s.inst_type != None and \ inst_type != "": inst_type = inst_type+", " if s.inst_type == 1: inst_type = inst_type+"Private, non-profit" if s.inst_type == 2: inst_type = inst_type+"Proprietary" if s.inst_type == 3: inst_type = inst_type+"Public" if s.inst_type == 4: inst_type = inst_type+"Private\"/\"Public" if inst_type == "": inst_type = "Not reported" print "<div class=\"feature\"><b>TYPE OF INSTITUTION</b></div>" print "<div class=\"detail\">" print "%s<br />" % (inst_type) print "<br /></div>\n" print "</td>\n<td>" print "<div class=\"feature\"><b>INSTITUTIONAL ACCREDITATION</b></div>" print "<div class=\"detail\">" agency = "" if s.accred == None: agency = "Not reported" if s.accred == 0: agency = "Not accredited by a regional association" elif s.accred == 1: agency = "New England Association of Schools & Colleges" elif s.accred == 2: agency = "Middle States Association of Colleges & Schools" elif s.accred == 3: agency = "Southern Association of Colleges & Schools" elif s.accred == 4: agency = "Western Association of Schools & Colleges" elif s.accred == 5: agency = "North Central Association of Colleges & Schools" elif s.accred == 6: agency = "Northwest Association of Schools & Colleges" print "%s<br />" % (agency) print "<br /></div>\n" if s.year_estab != None: print "<div class=\"feature\"><b>PROGRAM ESTABLISHED</b>" print "<span class=\"year\">%s</span><br />" % (s.year_estab) print "<br /></div>\n" if s.cert2000 in range (1,888) or \ s.assoc2000 in range (1,888) or \ s.ba2000 in range (1,888) or \ s.ma2000 in range (1,888) or \ s.doc2000 in range (1,888): print "<div class=\"feature\"><b>DEGREES AWARDED TO DEAF<br />STUDENTS IN 1999-2000</b></div>" print "<div class=\"detail\">" print "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"" print " summary=\"Degree, followed by number of students who earned that degree\">" if s.cert2000 in range(1,888): print "<tr>" print "<td class=\"tabdet\">Certificate: </td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (s.cert2000) print "</tr>" if s.assoc2000 in range(1,888): print "<tr>" print "<td class=\"tabdet\">Associate: </td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (s.assoc2000) print "</tr>" if s.ba2000 in range(1,888): print "<tr>" print "<td class=\"tabdet\">Baccalaureate: </td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (s.ba2000) print "</tr>" if s.ma2000 in range(1,888): print "<tr>" print "<td class=\"tabdet\">Master's degrees: </td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (s.ma2000) print "</tr>" if s.doc2000 in range(1,888): print "<tr>" print "<td class=\"tabdet\">Doctoral degrees: </td>" print "<td class=\"tabdet\" align=\"right\">%s</td>" % (s.doc2000) print "</tr>" print "</table>" print "<br /></div>\n" print "<div class=\"feature\"><b>EDUCATIONAL AND SUPPORT SERVICES</b><span class=\"super\">²</span></div>" print "<div class=\"detail\">" print "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\" cols=\"2\"" print " summary=\"Service, followed by availability\">" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Classroom communication practices:</b></td>" print "<td class=\"tabdet\">" if s.comacc != None: flags = "%8.8d" % (s.comacc) # Convert decimal number to binary string if flags[0:1] == "1": print "<b>·</b> Teachers who sign<br />" if flags[1:2] == "1": print "<b>·</b> Sign interpreting/transliteration<br />" if flags[2:3] == "1": print "<b>·</b> Oral interpreting<br />" if flags[3:4] == "1": print "<b>·</b> Cued speech<br />" if flags[4:5] == "1": print "<b>·</b> Deaf/blind interpreting<br />" if flags[5:6] == "1": print "<b>·</b> Real-time transcription<br />" if flags[6:7] == "1": print "<b>·</b> Group assistive listening devices<br />" if flags[7:8] == "1" and \ s.comacc_other != None: print "<b>·</b> %s<br />" % (s.comacc_other) else: print "Not reported" print "</td>" print "</tr>" if s.tutoring == 0: service = "Not offered" elif s.tutoring_who == 1: service = "Peer" elif s.tutoring_who == 10: service = "Professional" elif s.tutoring_who == 11: service = "Professional and peer" elif s.tutoring == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Tutors:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.notetaking == 0: service = "Not offered" elif s.notetaking_who == 1: service = "Volunteer" elif s.notetaking_who == 10: service = "Paid" elif s.notetaking_who == 11: service = "Paid and volunteer" elif s.notetaking == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Notetakers:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.vocservices == 0: service = "Not offered" elif s.vocservices_who == 1: service = "Personnel who use interpreters" elif s.vocservices_who == 10: service = "Personnel who sign" elif s.vocservices_who == 11: service = "Personnel who sign and use interpreters" elif s.vocservices == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Vocational services:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.perscouns == 0: service = "Not offered" elif s.perscouns_who == 1: service = "Personnel who use interpreters" elif s.perscouns_who == 10: service = "Personnel who sign" elif s.perscouns_who == 11: service = "Personnel who sign and use interpreters" elif s.perscouns == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Personal counseling services:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.placement == 0: service = "Not offered" elif s.placement_who == 1: service = "Personnel who use interpreters" elif s.placement_who == 10: service = "Personnel who sign" elif s.placement_who == 11: service = "Personnel who sign and use interpreters" elif s.placement == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Placement activities:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.deaforg == 0: service = "Not offered" elif s.deaforg == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Social/Cultural organizations:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.speechtherp == 0: service = "Not offered" elif s.speechtherp == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Speech therapy; Audiological services:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.slclassdeaf == 0 and \ s.slclasshearing == 0 and \ s.slclassteachers == 0: service = "Not offered" elif s.slclassdeaf == 1 or \ s.slclasshearing == 1 or \ s.slclassteachers == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Sign language classes:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" if s.remed == 0: service = "Not offered" elif s.remed == 1: service = "Available" else: service = "Not reported" print "<tr valign=\"top\">" print "<td class=\"tabdet\"><b>Remedial/Prep program:</b></td>" print "<td class=\"tabdet\">%s</td>" % (service) print "</tr>" print "</table>" print "<span class=\"foot\">² Services specific to deaf and hard of hearing students</span>" print "<br /></div>\n" print "</td></tr></table>" # print "</multicol>\n" print "<hr noshade width=\"30%%\" align=\"left\" />\n" print "<div class=\"foot\">¹ Full-time undergraduate for full academic year;<br />" print " international costs same as out-of-state unless reported.</div>" print "<hr noshade width=\"30%%\" align=\"left\" />\n" print "<a href=\"javascript:self.print()\">Print Current Page</a> | <a href=" print "\"/ccg/index.html\">Table of Contents</a> | <a href=\"/cgi-bin/schools.cgi\">Program" print "Index</a>" print "<hr noshade />" print "<!-- span class=\"c6\">Produced by Sequel, © Copyright Kevin Cole, Gallaudet" print "Research Institute 2001</span -->" footer() # Credits print "</body>" print "</html>" # # Frivolous stuff: Send e-mail to folks about the query just made. # # p = os.popen("/usr/sbin/sendmail -t", "w") # p.write("From: Linux God <kjcole@gri.gallaudet.edu>\n") # p.write("To: Kevin Cole <kjcole@pchb1f.gallaudet.edu>\n") # p.write("CC: Susan King <Susan.King@gallaudet.edu>\n") # p.write("Subject: Activating form\n") # p.write("\nSent: %s\n" % (right_now)) # p.write("\nInstitution: %s" % (institution)) # p.write("\nState: %s" % (state)) # schools.execute("select * from main where "+criteria) # for hits in schools.fetchall(): # for field in range(len(schools.description)): # p.write("\n%s: %s" % (schools.description[field][0],hits[field])) # smStatus = p.close()
#!/bin/bash ######################################################################### # NAME: school-fetch # AUTHOR: Kevin Cole <kjcole@gri.gallaudet.edu> # WHERE: Gallaudet Research Institute, Washington, DC 20002 # LASTMOD: 2001.08.01 # PURPOSE: This is a simple shell script that feeds data to a cgi-bin # file without using a form. I have to fool it into thinking it is # being called from a form. # USAGE: <a href="/cgi-bin/school-fetch?exact+string+with+pluses"> # exact string with pluses</a> # # Copyright (c) 2001 Kevin Cole <kjcole@gri.gallaudet.edu> ######################################################################### export REQUEST_METHOD="POST" export CONTENT_TYPE="application/x-www-form-urlencoded" export QUERY_STRING="match=exact&institution=$QUERY_STRING" export CONTENT_LENGTH=${#QUERY_STRING} echo $QUERY_STRING | /var/www/cgi-bin/query.cgi unset HTTP_USER_AGENT unset REQUEST_METHOD unset CONTENT_TYPE unset QUERY_STRING unset CONTENT_LENGTH