Page 282 -
P. 282
revised script
It’s time to exercise your newly acquired web-coding chops. You
were to grab your pencil and write the code for the generate_
timing_data.py CGI script. It’s not too different from the
generate_list.py code, so you should be able to reuse a lot of
your existing code.
#! /usr/local/bin/python3 This line is needed on Unix-based systems only.
import cgi
Import the
libraries and import athletemodel
modules you
intend to use. import yate
Get the data
from the athletes = athletemodel.get_from_store()
model.
Which
athlete’s form_data = cgi.FieldStorage()
data are
you working athlete_name = form_data['which_athlete'].value
with?
Nothing print(yate.start_response())
new here
or here. print(yate.include_header("Coach Kelly's Timing Data"))
print(yate.header("Athlete: " + athlete_name + ", DOB: " + Grab the
athlete’s name
athletes[athlete_name].dob + ".")) and DOB.
print(yate.para("The top times for this athlete are:")) Turn the top three list into
print(yate.u_list(athletes[athlete_name].top3())) an unordered HTML list.
The bottom of print(yate.include_footer({"Home”: "/index.html",
this web page
has two links. "Select another athlete": "generate_list.py"}))
A link back to the previous
CGI script.
246 Chapter 7