Created
January 31, 2014 09:23
-
-
Save theasder/8728915 to your computer and use it in GitHub Desktop.
Working with YQL through python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import urllib2 | |
import ast | |
def get_info(req): | |
base_url = "http://query.yahooapis.com/v1/public/yql?q=" | |
value = urllib.pathname2url(req) | |
rest = "&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=" | |
response = urllib2.urlopen(base_url + value + rest) | |
html = response.read() | |
return ast.literal_eval(html)#['query']['results']['quote'] just example of using YQL stocks | |
''' | |
dict_arr = get_info('select * from yahoo.finance.quote where symbol in ("YHOO","AAPL","GOOG","MSFT")') | |
print dict_arr | |
params = ['Name', 'Symbol', 'Change', 'LastTradePriceOnly', 'MarketCapitalization', 'DaysLow', 'DaysHigh', 'Volume', 'StockExchange', 'AverageDailyVolume', 'YearLow', 'YearHigh']· | |
for i in range(len(dict_arr)): | |
for st in params: | |
print st + ': ' + dict_arr[i][st] | |
print ' ' | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment