Skip to content

Instantly share code, notes, and snippets.

@yoshimov
Created September 1, 2016 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshimov/704a9fec8162cc4a1859cadb4e58f158 to your computer and use it in GitHub Desktop.
Save yoshimov/704a9fec8162cc4a1859cadb4e58f158 to your computer and use it in GitHub Desktop.
Fetch latest dweet data and append to spreadsheet
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