CSC 111: Introduction to Computer Science
HW 10: Classes and More Classes, with HTML
Due Wednesday April 20 Midnight, via Moodle
SUBMIT as HW10.py
Write a Table of FriendInfo to Your Webpage
Think about all you can do with your new knowledge and skills! You could:
- Find sites that post list of bestsellers, perhaps at different newspapers around the country,
and compare which books are popular everywhere, and which have a more regional following
- Grab info from financial pages to follow stock prices of your secret stock portfolio, in order
to alert yourself to buy or sell.
- Access an Amazon.com database and track the top sellers there, and create your own bestseller
list for a given genre of book.
- Music? Hobbies?
- Elections?
- Jobs and starting salaries?
So much information is posted on the web, and now you can get it automatically (with some work, of course).
(a) Overview
Back to what we've been working on... The homework this week is to create a table on your webpage that
has FriendInfo data that has been retrieved from the Smith Directory.
The final program you sumit should read in a text file called "NamesList.txt" that has a list of last
names, and creates an html table with the name, phone number and email for each person.
(b) Homework Details
The details (not in any particular order) for this program are:
- Organize your program logically into separate functions.
- Keep your .py file, and the .html file it creates, neat and easy to read.
- Use both class definitions we developed this week in class -
FriendInfo.py and
getURLinfo.py.
- Read the list of last names from an input file "NamesList.txt," and create a simple Python
list of these names (the strings).
- Create a list of FriendInfo objects, that of course initially will be the empty list.
- Do not edit or alter the FriendInfo.py file in anyway - you must use it as is
- Create getURLinfo objects to retrieve the name, phone number and email address from the Smith
Directory. The base URL that you can use for this is
"http://www.smith.edu/global_campusdirectory.php?name=%s"
- Do not edit or alter the getURLinfo.py file in anyway - you must use it as is
- As these pieces of information are obtained, use them to create FriendInfo objects, and append
each new FriendInfo object to the list of FriendInfo objects.
- After you have your complete list of FriendInfo objects, write the information in this list of
objects out to a nicely formatted HTML table on your webpage.
(c) Smith Directory Details
You will need to be careful about the capitalization of the name as it is used in the base URL. As you
search through the page source to retrieve your desired information, try
searching both for occurrences of the name all in lower case, as well as names that are capitalized. You
might find useful tags with one form and not the other. For the name
that you include in your table, print it out as first name and then last name. For example, if "cardell"
were to be in the input file, then the final HTML table should have (with or
without the middle initial):
| Name |
Phone |
email |
| Judith Cardell |
585-4222 |
jcardell@smith.edu |
For the phone number, feel free to use the "(413)" as a tag, and then you could, or not, include that in
your table.
Finally, for the email, you could either obtain it from the webpage, as you are the other information, or
you could actually construct it yourself using Python's string processing.
(d) What to Sumbit
Submit a program that expects no user input. Instead, your program will read in a list of last names from a
text file, called NamesList.txt, and the names could have any capitalization
in this file. (This means that you will want to do something to make them all lowercase, if that is how
you need to use them in the base URL, for example.) Your program will create a
webpage (.html file) that has basic elements, such as your name. This webpage will also have a table of
information retrieved from the Smith Directory.
You can retain any other elements from previous assginments, or make this a simple page with just your name(s)
and a beautiful table.
If you do retain other elements, include any "user_input" information in your file directly - don't require
any user input from me. I will still have a generic jpeg file though, so if you want to
include images, just be sure to change the name of all the expected jpeg files to "HW10image.jpg" before
you submit your program. Therefore, you can assume that I will
have a directory. That directory will contain:
- Your python program, HW10.py
- FriendInfo.py
- getURLinfo.py
- NamesList.txt
- HW10image.jpg
It will not contain anything else, until I run your program. When I run your program, it will create a
HW10.html file that I can view.
That's it for this week - two class definitions creating two types of objects, with the data that you
retrieve being compiled into a list of objects and then displayed in an HTML table.
A sample solution program can be viewed
here.