Info
Content

Napojení na Google Sheets

Tabulka pro nastavení přístupu:

Parametr Hodnota
Hostname: https://db.hexio.cloud
Database: Název vaší databáze
Username: Vaše jméno k databázi
Password: Vaše heslo k databázi

Google Script:

function FetchInfluxData(hostname, username, password, database, query, _x) {

  var encodedAuthInformation = Utilities.base64Encode(username + ":" + password);
  var fetchOptions = {headers: {Authorization: "Basic " + encodedAuthInformation}};

  var jsondata = UrlFetchApp.fetch(
    hostname + "/query?db=" + encodeURIComponent(database) + "&q=" + encodeURIComponent(query),
    fetchOptions
  );

  var data = JSON.parse(jsondata.getContentText());
  var result = [[], []];
  var colIndex = 0;
  
  if (!data.results) return null;
  
  // Iterate over results
  for (var i = 0; i < data.results.length; i++) {
   
    // Iterate over series
    for (var j = 0; j < data.results[i].series.length; j++) {
     
      var serie = data.results[i].series[j];
      
      // Add serie header
      result[0][colIndex] = serie.name;
      
      for (var c = 0; c < serie.columns.length; c++)
        result[1][colIndex + c] = serie.columns[c];
      
      // Add data
      for (var v = 0; v < serie.values.length; v++) {
       
        if (!(result[2 + v] instanceof Array))
          result[2 + v] = [];
        
        for (var c = 0; c < serie.values[v].length; c++)
          result[2 + v][colIndex + c] = serie.values[v][c];
        
      }
      
      // Increment col index
      colIndex += serie.columns.length;
      
    }
    
  }
  
  // return JSON.stringify(data, null, 4);
  return result;
}
No Comments
Back to top