0

I am building a Flask site. The client will access a page into which they will enter a stock ticker, submit it to Yahoo Finance and retrieve the name, price, and symbol of the security. The data will be rendered on a separate template. Modules used include Flask and urllib.request.

It seems I am Googling the incorrect terminology. Could someone point me in the direction of the correct search terms?

davidism
  • 121,510
  • 29
  • 395
  • 339
Ryan
  • 1,312
  • 3
  • 20
  • 40
  • 3
    You need to make a call out to the external API using either `requests`, `urllib3` or a library designed for retrieving data from Yahoo Finance. You can then modify the result (if needed) and return it to the user. – Suever Feb 08 '17 at 02:44
  • @Suever - Sounds good to me. At least now I know where to look. Many thanks! – Ryan Feb 08 '17 at 02:50

2 Answers2

1

It seems to me that you need to use the Yahoo Finance API to get the data you need.

See this question:

yahoo finance stock quote api

Here is Yahoo Developer Network:

https://developer.yahoo.com/

Unless I misunderstood your question, I think this is the direction you need to go.

Otherwise, you could set up an iFrame and GET into that. But somehow I don't think that's what you're after.

Community
  • 1
  • 1
nicorellius
  • 3,715
  • 4
  • 48
  • 79
1

The following snippet plus 2 html pages including Jinja to extend an underlying layout did the trick. The heart of the (stock ticker) lookup function (below) came from stackoverflow, and I added functionality. As noted last night, it really did come down to search terms and learning the vocabulary/jargon of Flask. Thanks again to those who participated.

# http://stackoverflow.com/a/21351911
try:
    url = "http://download.finance.yahoo.com/d/quotes.csv?f=snl1&s={}".format(symbol)
    webpage = urllib.request.urlopen(url)
    datareader = csv.reader(webpage.read().decode("utf-8").splitlines())
    row = next(datareader)
except:
    return None
Ryan
  • 1,312
  • 3
  • 20
  • 40
  • 1
    Cool. Glad you found something that worked. It's too bad someone had to down vote your OQ. Hopefully that won't be too discouraging moving forward with SO. – nicorellius Feb 09 '17 at 01:50