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)
:)
#!/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)
:)