Last active
May 14, 2020 02:22
-
-
Save jaredwolff/3cda7fd3fb75ad928be70ffcb9fd9c7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this is a function that fires when the webapp receives a POST request | |
function doPost(e) { | |
//Return if null | |
if( e == undefined ) { | |
Logger.log("no data"); | |
return HtmlService.createHtmlOutput("need data"); | |
} | |
//Parse the JSON data | |
var event = JSON.parse(e.postData.contents); | |
var data = JSON.parse(event.data); | |
//Get the last row without data | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var lastRow = Math.max(sheet.getLastRow(),1); | |
sheet.insertRowAfter(lastRow); | |
//Get current timestamp | |
var timestamp = new Date(); | |
//Insert the data into the sheet | |
sheet.getRange(lastRow + 1, 1).setValue(event.published_at); | |
sheet.getRange(lastRow + 1, 2).setValue(data.temperature); | |
sheet.getRange(lastRow + 1, 3).setValue(data.humidity); | |
sheet.getRange(lastRow + 1, 4).setValue(data.pm10); | |
sheet.getRange(lastRow + 1, 5).setValue(data.pm25); | |
sheet.getRange(lastRow + 1, 6).setValue(data.tvoc); | |
sheet.getRange(lastRow + 1, 7).setValue(data.c02); | |
SpreadsheetApp.flush(); | |
return HtmlService.createHtmlOutput("post request received"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment