谷歌脚本中的天气API修改

时间:2015-03-18 19:12:44

标签: highcharts

我在google工作表中运行一个脚本,该脚本使用来自Wunderground的API来收集我当地的天气。我现在遇到问题,当我尝试使用highcharts时,因为它不喜欢来自API json的%符号。我的代码如下,我正在试图弄清楚如何修改它

<Code>
/**
 * 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
 * https://developers.google.com/apps-script/service_spreadsheet
 */
var cDay = 0, cTemp = 1, cRH = 2, cWinddegree = 3;
var cWindspeed = 4, cWindgust = 5;
var nCols = 7;



function getTemp() {
  var url = 'http://api.wunderground.com/api/***************/conditions/q/44.1,-77.3.json';
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange();
  var numRows = rows.getNumRows();
  var response = UrlFetchApp.fetch(url);

  var contentText = response.getContentText();
  var conditions = JSON.parse(contentText);
  var todaysConditions = conditions; 

  var temp = todaysConditions.current_observation.temp_f;
  var rh = todaysConditions.current_observation.relative_humidity;
  var winddir = todaysConditions.current_observation.wind_dir;
  var winddegree = todaysConditions.current_observation.wind_degrees;
  var windspeed = todaysConditions.current_observation.wind_mph;
  var windgust = todaysConditions.current_observation.wind_gust_mph;
  sheet.insertRowAfter(1);

  var range = sheet.getRange(2,1,1, nCols);
  var row = range.getValues()[0];
  row[cDay] = new Date ();
  row[cTemp] = temp; 
  row[cRH] = rh;
  row[cWinddegree] = winddegree;
  row[cWindspeed] = windspeed;
  row[cWindgust] = windgust;



  range.setValues([row]);

}
</Code>

我相信我需要修改这条线: row [cRH] = rh;

0 个答案:

没有答案