CSE 1710.03A Programming for Digital Media
Lab 09
Due date: Nov 16, 2009 at 20:00
Changing a WWW page
Assume you are given a WWW page that has lot's of dates in it and your
task is to change some of the dates. For simplicity,
this lab will concentrate only on years.
As an example scenario for this task, you are given a copy of the
WWW page for the History of Austria.
Assuming that historical research has shown that all records for the
period from 1700 to 1799 are off by two years, you are now asked to
fix all dates by decreasing each year number in that interval by two.
For this, you have to write a function
fixDates(originalfile,output)
which reads the file named originalfile and writes
the result to the file named output.
You must name your program lab09.py.
As a starting point, you can use the following code segment,
which opens a file, checks if the text "WINNER" appears in it and
prints also the name that appears after the word WINNER in the text.
file = open(name,"rt")
text = file.read()
# Search for WINNER followed by a space and a 10 character name
position = text.find("WINNER")
if position <> -1:
print "Found a Winner:", text[position+8:position+18]
file.close()
Here are a couple of hints:
-
Search for the string "17". To make sure that you are not changing
other dates (e.g. 1917 or 1176), you have to check that the next
two characters after an occurence of "17" are both digits. You
can do this with the method string.isdigit().
If you find a date in the 1700-1799 range, you then can extract
it and convert to a number with the int() function and
subtract two. Then use the str()function to convert
the number to a string, which you can now use to replace the original
text.
-
Don't forget to write the changed text to the file specified by the
second argument.
-
Right click on the link to the Wikipedia article above and choose
"Save As ..." to create a local copy in your directory.
-
You only have to change the main .html file. No changes are necessary
in the files that are references by the mail .html file.
-
You can safely ignore the effect of the replacement onto any links
that contain the string "17" followed by 2 numbers.
What to Turn in
As mentioned previously, you have to add comments with
your own identification (name, student ID, date).
Remember to save the file after you modify it!
How to submit the lab
For details on how to submit, please refer to lab2. However, this time please
submit to lab09, i.e. issue the command
submit 1710 lab09 lab09.py
Note: You must do all the above steps correctly for receiving
full credit for this labtest.