# License Information # This code is released under the BSD License. # This information must be retained any any releases or changes made to this code. # If you use or make changes to this code, please email andrew@digicool.com # I'd like to know who is using this and what kind of changes might be considered # for incorporation to a future package I'm currently working on. import httplib, string, re version = "0.1" author = "Andrew Sawyers, Dec. 2000" def getQuote(sname): http = httplib.HTTP('finance.yahoo.com') http.putrequest('GET', '/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv'%sname) http.putheader('Accept', 'text/html') http.putheader('Accept', 'text/plain') http.endheaders() httpcode, httpmsg, headers = http.getreply() if httpcode != 200: raise "Could not retrieve document" doc = http.getfile() data = doc.read() data = re.sub('"', '', data) array = string.split(data, ",") doc.close() symbol = array[0] last = array[1] date = array[2] time = array[3] change = array[4] qopen = array[5] high = array[6] low = array[7] volume = array[8] return {'symbol':symbol, 'last':last, 'date':date, 'time':time, 'change':change, 'qopen':qopen, 'high':high, 'low':low, 'volume':volume} if __name__=="__main__": print getQuote()