Testing this type of program can be difficult if you don't have a permanent Internet connection. This program works around this by providing a mode where it loads data from a text file instead of from the Web. If the USE_TEST_FILE constants is defiend as True, the program reads data from a text file. Otherwise it uses the Internet Transfer control (Inet) to send a query to a Yahoo stock server and reads the results.
The following code builds a query string similar to the following, which fetches stock quotes for DIS, COKE, amd MCI:
http://quote.yahoo.com/download/quotes.csv?format=sl&ext=.csv&symbols=mci,dis,coke,pep
It uses the Inet control's OpenURL method to open the URL and read the result. The result is text similar to the following:
"MCI",22.61,"5/23/2003","3:20pm",-0.17,22.60,22.75,22.45,5600
"DIS",18.24,"5/23/2003","4:01pm",+0.12,18.25,18.35,18.20,6044400
"COKE",50.23,"5/23/2003","3:59pm",-0.47,50.46,50.68,50.00,4800
"PEP",43.56,"5/23/2003","4:01pm",-0.17,43.62,43.80,43.35,2389000
Notice that this isn't HTML so it will probably confuse your browser. The program, however, has no trouble displaying the resulting text.
|