PDA

View Full Version : stock quote program


inkedmn
03-17-2002, 09:27 PM
this script grabs stock quotes from yahoo.com and prints them out.


#!/usr/bin/env python

# grabs stock quotes

def stockQuote(symbol):
import urllib2, string, sys
newsymbol = symbol.upper()
base = 'http://finance.yahoo.com/d/quotes.csv?s='
tail = '&f=sl1d1t1c1ohgv&e=.csv'
url = base+symbol+tail
try:
quote = urllib2.urlopen(url).read()
except Exception, e:
print e
sys.exit()
splitquote = quote.split(',')
if splitquote[1] != "0.00":
print "The current price of %s is %s" % ((splitquote[0])[1:-1] , splitquote[1])
else:
print "Sorry, I couldn't find that one"
symbol = raw_input("Enter a ticker symbol: ")
stockQuote(symbol)


:)

kmj
03-18-2002, 11:32 AM
very qool. I was thinking of doing something similar with snow reports from various ski resort websites.

Ludootje
03-19-2002, 04:11 PM
You 2 are so damn good in programming. I think it's a gift or something like that, you understand it or you don't. And I'm affraid I don't :(
Or I just don't want to spend my time on learning it :o

kmj
03-19-2002, 04:20 PM
lol; it's not that hard, but it does take time. Heck, most of the work is already done for you in the libraries. You do have to want to do it, though.

inkedmn
03-19-2002, 09:35 PM
Originally posted by kmj
lol; it's not that hard, but it does take time. Heck, most of the work is already done for you in the libraries. You do have to want to do it, though.

i wholeheartedly agree...

i think part of the reason i pick this stuff up fairly quickly is because it think it's a pantload of fun :)

don't be afraid to try it. we all suck in the beginning... ;)