Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
まいにち体調管理アプリの Google Spreadsheet 連携用サンプルコード
function myFunction() {
Logger.log(ScriptApp.getOAuthToken())
}
function doPost(e) {
var status = 0
let jsonString = e.postData.getDataAsString()
let json = JSON.parse(jsonString)
if (json.date) {
let year = json.date.year
let month = ('00' + json.date.month).slice(-2)
let day = ('00' + json.date.day).slice(-2)
let sheetName = year + month
let spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
var sheet = spreadsheet.getSheetByName(sheetName)
if (!sheet) {
spreadsheet.insertSheet(sheetName)
sheet = spreadsheet.getActiveSheet()
sheet.appendRow([
"日付","時間帯","体温",
"咳","鼻水","痰","息切れ","喉の痛み","眼の痛み","筋肉痛","頭痛",
"下痢","嘔吐","倦怠感","におい","味","解熱剤の服用"
])
}
let dateString = year + '/' + month + '/' + day
for (const condition of json.conditions) {
sheet.appendRow([
dateString, condition.time_zones, condition.body_temperature,
condition.cough, condition.runny_nose, condition.phlegm, condition.breathless,
condition.sore_throat, condition.eye_pain, condition.muscle_pain, condition.headache,
condition.diarrhea, condition.vomiting, condition.malaise, condition.smell, condition.taste,
condition.antipyretic
])
}
}
else {
status = 500
}
const result = {
"status": status
}
const response = JSON.stringify(result)
return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.JSON)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment