Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

for dj: eventcal.py with cgi traceback

infidelinfidel Posts: 2,900Member
I just read about a cool new (as of Python 2.2, I believe) module called cgitb that helps in debugging cgi scripts by printing exceptions to the browser instead of returning a 500 error. This might help us figure out what is causing your error.

[code]
#!/usr/bin/python

[red]import cgitb; cgitb.enable()[/red]

# http header
print "Content-type: text/html
"

# define calendar functions
import calendar
import time

weekdays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']

def CalendarHTMLTable(year, month, events = {}):
# make Sunday the first day of the week
calendar.setfirstweekday(calendar.SUNDAY)

# get the time value
caltime = (year, month, 0, 0, 0, 0, 0, 0, -1)

# get the matrix of calendar days
calmatrix = calendar.monthcalendar(caltime[0],caltime[1])

# begin calendar html table
html = ''
html = html + ''
html = html + ''
html = html + ''

# calendar header
html = html + ''
html = html + ''
html = html + '"
html = html + ''
html = html + ""

# weekday names
html = html + ""
for day in range(7):
html = html + ""
html = html + ""

# calendar body
for week in calmatrix:
html = html + ""
for day in week:
if day == 0:
html = html + ""
else:
html = html + ""
html = html + ""

# close up calendar table
html = html + "
' +
'' +
'
' +
time.strftime("%B %Y", caltime) + "
' +
'' +
'
" + weekdays[day] + "
"
html = html + str(day) + "
"
if events.has_key(day):
eventlist = events[day]
for event in eventlist:
html = html + ''
html = html + event["time"] + ": " + event["title"] + "
"
html = html + '
'
html = html + "
"

# return the html table
return html

if __name__ == '__main__':
# get parameters
import cgi
form = cgi.FieldStorage()
if form.has_key("year"):
year = int(form["year"].value)
else:
year = time.localtime()[0]
if form.has_key("month"):
month = int(form["month"].value)
else:
month = time.localtime()[1]
if form.has_key("next.x"):
month += 1
if month > 12:
month = 1
year += 1
if form.has_key("prev.x"):
month -= 1
if month < 1:
month = 12
year -= 1

# spit out html calendar displaying events
print ""
print CalendarHTMLTable(year,month)
print ""
[/code]


[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Comments

  • djshadmegodjshadmego Posts: 27Member
    : I just read about a cool new (as of Python 2.2, I believe) module called cgitb that helps in debugging cgi scripts by printing exceptions to the browser instead of returning a 500 error. This might help us figure out what is causing your error.

    This is great, but will it work in 2.1? that is the version on my site.
    There is also a flash of inspiration I had while being frustrated over the fact that I can't run this script.
    I have to change something in the line of code here:
    [code]# begin calendar html table
    : html = ''
    [/code]
    This part confused me when I installed it before and I can't rememebr what you said to insert when installing the script.
    Could this be where the problem lies?
    If it is, what need I change about this snipet of code to make the calendar work?
    : [code]
    : #!/usr/bin/python
    :
    : [red]import cgitb; cgitb.enable()[/red]
    :
    : # http header
    : print "Content-type: text/html
    "
    :
    : # define calendar functions
    : import calendar
    : import time
    :
    : weekdays = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
    :
    : def CalendarHTMLTable(year, month, events = {}):
    : # make Sunday the first day of the week
    : calendar.setfirstweekday(calendar.SUNDAY)
    :
    : # get the time value
    : caltime = (year, month, 0, 0, 0, 0, 0, 0, -1)
    :
    : # get the matrix of calendar days
    : calmatrix = calendar.monthcalendar(caltime[0],caltime[1])
    :
    : # begin calendar html table
    : html = ''
    : html = html + ''
    : html = html + ''
    : html = html + ''
    :
    : # calendar header
    : html = html + ''
    : html = html + ''
    : html = html + '"
    : html = html + ''
    : html = html + ""
    :
    : # weekday names
    : html = html + ""
    : for day in range(7):
    : html = html + ""
    : html = html + ""
    :
    : # calendar body
    : for week in calmatrix:
    : html = html + ""
    : for day in week:
    : if day == 0:
    : html = html + ""
    : else:
    : html = html + ""
    : html = html + ""
    :
    : # close up calendar table
    : html = html + "
    ' +
    : '' +
    : '
    ' +
    : time.strftime("%B %Y", caltime) + "
    ' +
    : '' +
    : '
    " + weekdays[day] + "
    "
    : html = html + str(day) + ""
    : if events.has_key(day):
    : eventlist = events[day]
    : for event in eventlist:
    : html = html + ''
    : html = html + event["time"] + ": " + event["title"] + ""
    : html = html + '
    '
    : html = html + "
    "
    :
    : # return the html table
    : return html
    :
    : if __name__ == '__main__':
    : # get parameters
    : import cgi
    : form = cgi.FieldStorage()
    : if form.has_key("year"):
    : year = int(form["year"].value)
    : else:
    : year = time.localtime()[0]
    : if form.has_key("month"):
    : month = int(form["month"].value)
    : else:
    : month = time.localtime()[1]
    : if form.has_key("next.x"):
    : month += 1
    : if month > 12:
    : month = 1
    : year += 1
    : if form.has_key("prev.x"):
    : month -= 1
    : if month < 1:
    : month = 12
    : year -= 1
    :
    : # spit out html calendar displaying events
    : print ""
    : print CalendarHTMLTable(year,month)
    : print ""
    : [/code]

    [hr][size=4][blue][b]D[/b][/blue][/size][size=5][italic][grey][b]J[/b][/grey][/italic][/size]

  • infidelinfidel Posts: 2,900Member
    : : I just read about a cool new (as of Python 2.2, I believe) module called cgitb that helps in debugging cgi scripts by printing exceptions to the browser instead of returning a 500 error. This might help us figure out what is causing your error.
    :
    : This is great, but will it work in 2.1? that is the version on my site.
    : There is also a flash of inspiration I had while being frustrated over the fact that I can't run this script.
    : I have to change something in the line of code here:
    : [code]# begin calendar html table
    : : html = ''
    : [/code]
    : This part confused me when I installed it before and I can't rememebr what you said to insert when installing the script.
    : Could this be where the problem lies?
    : If it is, what need I change about this snipet of code to make the calendar work?

    I think you mentioned this in your mail message. I don't know why this would cause problems on an initial load since it's really just text. But if changing the URL of the ACTION attribute to a full path helps then cool.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.