CS074-The Digital World

    Lab 10



Assigned Wednesday, April 22
Due Friday, May 1

In this final assignment, you will use write Python programs to get information from websites, process the information, and display it (sometimes in another web page).

While there are two problems, you are only expected to do one of them.  Each of the two problems has multiple parts, with varying degrees of difficulty.  You get some credit for doing the simple parts of one problem, full credit for doing all of them.

1. In this problem, you will enhance the stock price programs demonstrated in class in several different ways.

(a) (6 pts) Revise the DowJones program so that the output is printed in nice even columns, instead of the present jagged columns. A lazy way to do the problem is to pad the names of the original companies with spaces so that they all have the same number of characters.  You'll get only four points for this---as a penalty for laziness!  It's better to use unpadded company names, and have the program itself calculate how many extra spaces to print.

(b) (10 pts---but you can't get credit  for both this and part (a))  Revise the Dow Jones program so that the output is displayed in a web page created by the program.  The web page should display the data in a table, so you will need to figure out how to generate the HTML for a web page that contains a table.  To do this, look at the source for this page.

(c) (7 points) Revise the getStockPrice2 function so that it returns a list of three strings:  The third string should be something like "-0.20", or "+1.05", which gives the change in the stock price since the last market close.  You will have to scrutinize the crucial line of the HTML generated by the Yahoo! site in order to figure out exactly how this information is encoded, and how to extract it. You should also revise the function testGetStockPrice2 to accommodate this.

(d) (3 points) Now use this to revise the Dow Jones program so that it also displays the change in the value of each stock, as well as the change in the Dow Jones Industrial Average. (You have to do part (c) to do this.)

(e) You get 20 points for combining (b) and (d):  Both a web page display of the data in a table, along with enhanced data that includes the change in rice.


2. This problem gets Latitude and Longitude information for addresses in the United States using the website www.geocoder.us.  You should try this out with an ordinary web browser to see what it does.

You should note that when you enter the address data in a form like:

63 Menotomy Rd., Arlington, MA

it actually appears in the URL of the response page as:

http://geocoder.us/demo.cgi?address=63+Menotomy+Rd.%2C+Arlington%2C+MA

In order to convert the address data you type into a form that your Web browser can understand, you can use the function quote in the urllib library of Python.  Here's a brief example typed into the command window in JES.



I have provided a function that takes the latitudes and longitudes of two points on the Earth and returns the distance in miles between them (the distance along a "great Circle" route, the shortest path between them).  You should incorporate this into your work below.

(a) (10 points) Write a python program that asks the user for two addresses, then displays the distance between them, using information that the program obtains from the geocoder website.

(b) (15 points--you can't get credit for both parts (a) and (b))  Write a program that displays the information in a web page created by the program.  The page should contain the addresses, the latitudes and longitudes, and the distance in both miles and kilometers.

(c) (5 points)  For an extra 5 points, have the web page of part (b) include a map---obtained from Google Maps---showing the two locales.  I'll have some explanation about how to do this, but I'm still figuring it out myself!  Check back later.