Computer Science 111, Fall Semester, 2006
Homework #11
due: by midnight December 13, 2006
Your task in this week's project is
expand your Hw10 to include a search function that searches your siteList
and to write an html file with the results.
getcopy hw11demo.pyc
for a demonstration. You can make your user interface a little more
friendly than this one. But do not add any inputs!
After you run the function, look at the file hw11Results.html.
Preliminary Work
Do the following:
- If your hw10.py does not work, start with mine, which
is in the file hw10demo.py (use getcopy to get this).
-
copy hw10.py into public_html/hw11.py
If you are using the demo program, do
cp hw10demo.py public_html/hw11.py
- Now change directories so that
you are in your public_html directory:
cd public_html
and get a copy of the sites
file, called cdsites.txt. Since you are
in the public_html directory, when you type:
getcopy cdsites.txt
cdsites.txt will be placed in your public_html directory.
- Keep your main and selSort functions intact.
Make your siteList searchable
-
Now get a copy of searchExample.py from the handout directory:
getcopy searchExample.py
Insert the function definition for search() into your hw11.py file.
Modify it so its second formal parameter is called
siteList instead of nums, and also so it compares
Site ProductNames instead of numbers.
- After main() writes out the sorted Site objects to the
file cdSitesSorted.txt,
create a new empty list and assign it to
a variable called foundList. We will construct a while loop to search
through siteList, and everytime we find a matching Site object
we will append it to foundList. Do this by following the
next instructions.
- Insert another while loop just after initializing foundList to
be the empty string.
This loop is constructed just like the previous one.
- Just before the while loop, it asks the user if
she/he wants to search for a site ProductName.
- The loop condition checks for "yes" or "Yes"
and the body of the loop first asks the user for the ProductName to search for.
- Make sure to change the string they enter to all upper case letters
before passing it to the search function.
- Next call the search function, passing it the upper case string.
-
If the search function does not return a value of -1
that means it has found a site and the value it returns
is the index of the found Site object.
The found Site object will be a member of
siteList, and its index is returned by the search function. Append
this site Object to foundList, but only if the index is not -1.
If it is found, also Print the Site object out (use your printSite() function).
- Get the modified program to interpret and work before going to the
next step.
After the search loop, define and call a function to write out an html file with the
information from the Site objects that were found.
After the search loop, define a new function that
generates an html file in this way:
- The function will have two formal parameters:
- foundList - the list of instances of Site that were found in the search loop
- headerString - A string you choose for the header at the top of the web page,
that reflects the contents of the page.
- The function
will create an html file called hw11Results.html
with all the found Site instances listed as web links
(review how you generated an html file and
generated a bullet list in html from hw6/Lab6.
getcopy hw6demo.py if you need to).
- First generate a header (using the <H2> header </H2> html tags)
that is the headerString that was passed as the second parameter.
-
Then loop through
your foundList and make an html list item for each
Site object.
To create a link after the <li> in your list,
you will use html anchor tags as list entries like this:
artist: <a href="URL"> ProductName</a>
An actual example would be
<b>santana</b>: <a href="http://www.amazon.com/exec/obidos/ASIN/B00097DXZS/webservices-20?dev-t=1JRMKNR4RPZWY2VBKW02%26camp=2025%26link_code=xm2"> <b>ALL THAT I AM</b>.
</a>
where
<b>santana</b>
is the Site object artist name, with html boldface tags around it,
http://www.amazon.com/exec/obidos/ASIN/B00097DXZS/webservices-20?dev-t=1JRMKNR4RPZWY2VBKW02%26camp=2025%26link_code=xm2
is the Site object URL
(notice that the URL must be in double quotes, just as the image file URL had to be in
hw6),
and
<b>ALL THAT I AM</b>
is the ProductName with html boldface tags around it.
- Then at the end of your main() definition, call the function to generate the html file and pass it
the parameters
siteList and "The string you want to use for the header"
- Make sure the permissions are set for this file:
chmod a+r hw11Results.html
and check the web page in a browser to make sure it is correct.
This is important! Amazon returns full URLs with
"http://" in front of them already. Remember that we
had to add that to our URLs for hw6. So make sure the href
does not have more than one
"http://" in the string.
Submit the homework by typing
submit homework11 hw11.py
Important Note: In homework 11, you
must provide documentation for all functions.
i.e. Just before the function definition, include a
banner, in comments, that says the function name,
what it takes for arguments and what it returns,
and what task it performs.
I will test your program by accessing your web site, and also by
examining your hw11.py file.
p.s. This has been one of my favorite csc111 classes ever!