I am trying to use a script from within google spreadsheet to populate weather data that I an use in other apps and my webpage with highcharts. My coding skills are weak and I in the process of educating myself. I wrote this code based on an example I found but it doesn't run. I get the following TypeError: Cannot read property "simpleforecast" from undefined. (line 21, file "Code")
My main goal is to log temp,humid,windspeed,direction.
My main goal is to log temp,humid,windspeed,direction.
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* <a href="https://developers.google.com/apps-script/service_spreadsheet" rel="nofollow">https://developers.google.com/apps-sc...</a>
*/
var cDays = 0, cHigh = 1, cLow = 2, cConditions = 3, cSparkline = 4;
var nClols = 5;
function getTemp() {
var url = '<a href="http://api.wunderground.com/api/************/forecast/q/ON/Belleville.json" rel="nofollow">http://api.wunderground.com/api/*****...</a>';
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var response = UrlFetchApp.fetch(url);
var contentText = response.getContentText();
var forecast = Utilities.jsonParse(contentText);
var todaysForecast = forecast.forecast.simpleforecast.forecastday[0];
var high = todaysForecast.high.fahrenheit;
var low = todaysForecast.low.fahrenheit;
var conditions = todaysForecast.conditions;
sheet.insertRowAfter(1);
var range = sheet.getRange(2,1,1, nCols);
var row = range.getValues()[0];
row[cDay] = new Date ();
row[cHigh] = high; row[cLow] = low;
row[cConditions] = conditions;
var nRows= numRows >= 10 ? 10 :numRows;
row[cSparkline] = "=SPARKLINE(R[0]C[-3]:R[" + (nRows-1) + "]C[-3])";
range.setValues([row]);
}
<code>
I figured if I could get this to work I could modify to get exactly what I want.
any advice,example or direction is greatly appreciated!
Thanks
Jeff in Ontario