#!/usr/bin/python
# by manny juan
# manny@jps.net
# 9/14/1997
"""A `month' cgi script that uses the cgi module."""
from calend2 import *
import cgi, string
def prhtml(year,mth):
weeks=monthcalendar(year,mth,0)
print '',month_name[mth],year,''
print '''
| Sunday |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |
'''
for week in weeks:
print ''
for day in week:
print '| 0):
print 'width=5>',day,
else:
print '>',
print ' | | '
print '
'
print ''
for day in week:
print '',
if(day>0):
print '
'
print ' | '
print '
'
print '''
'''
def go():
print "Content-type: text/html" # identify response as HTML
print # end of headers
print "cal2htm.py - Calendar To HTML with Python"
try:
# eg query = "mth=9&year=1997"
try:
# have the cgi module parse the data for you...
form = cgi.FieldStorage()
MField = form["mth"]
YField = form["year"]
except (KeyError, TypeError):
print "Sorry, I need both Month and Year"
raise SystemExit
# get the values of the fields
try:
M = MField.value
Y = YField.value
except AttributeError:
print "Sorry, Multiple months or multiple years are not allowed."
raise SystemExit
# convert the year to a number
try:
year = string.atoi(Y)
mth = string.atoi(M)
except ValueError:
print "
OOPS: year or month isn't a number (!) "
raise SystemExit
prhtml(year, mth)
finally:
print '
Calendar automatically generated by Python script ',
print 'cal2htm.cgi',
print " found at manny juan's python page"
print ""
if __name__=="__main__":
go()