...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var yahooFinanceQuery='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='; var yahooFinanceData=JSON.parse(http.get(yahooFinanceQuery)); var apple=yahooFinanceData.query.results.quote[0]; var google=yahooFinanceData.query.results.quote[1]; var microsoft=yahooFinanceData.query.results.quote[2]; context.set("google",google); context.set("microsoft",microsoft); context.set("apple",apple); |
LINE DESCRIPTIONS:
1: Created a variable to hold the url that calls the query
2: Call the url using http object get function and parse the result into a JSON object at the same time
3,4,5: Create variables to hold each symbol stock market data info
6,7,8: Use context object to attach those variable to this page context so other Javascript Runner macros in this page be able to access those