Skip to content

Instantly share code, notes, and snippets.

@markandey
Created May 23, 2013 05:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save markandey/5632923 to your computer and use it in GitHub Desktop.
Save markandey/5632923 to your computer and use it in GitHub Desktop.
pulls data from YQL and puts in a spreadsheet
function pullData() {
//select * from yahoo.finance.quote where symbol in ("YHOO","AAPL","GOOG","MSFT")
var url="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var response = UrlFetchApp.fetch(url);
var json=JSON.parse(response.getContentText());
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var quotes=json.query.results.quote;
for(var i=0;i<quotes.length;i++){
col=i+1;
sheet.getRange('a'+col).setValue(quotes[i].Name);
sheet.getRange('b'+col).setValue(quotes[i].LastTradePriceOnly);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment