Skip to content

Instantly share code, notes, and snippets.

@theasder
Created January 31, 2014 09:23
Show Gist options
  • Save theasder/8728915 to your computer and use it in GitHub Desktop.
Save theasder/8728915 to your computer and use it in GitHub Desktop.
Working with YQL through python
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