Created
September 1, 2016 02:42
-
-
Save yoshimov/704a9fec8162cc4a1859cadb4e58f158 to your computer and use it in GitHub Desktop.
Fetch latest dweet data and append to spreadsheet
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
function addData(time, val) { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var last = sheet.getLastRow(); | |
var cell = sheet.getRange(last, 1); | |
var pretime = cell.getValue(); | |
if (pretime != time) { | |
cell.offset(1, 0).setValue(time); | |
cell.offset(1, 1).setValue(val); | |
} | |
} | |
function pullData() { | |
var url="http://dweet.io/get/latest/dweet/for/xxx"; | |
var res = UrlFetchApp.fetch(url); | |
var json = JSON.parse(res.getContentText()); | |
var time = json["with"][0].created; | |
var val = json["with"][0].content.light; | |
addData(time, val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment