Skip to content

Instantly share code, notes, and snippets.

@gre
Created December 23, 2017 09:12
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 gre/1d3a2b164e7061475fc18df818a2a925 to your computer and use it in GitHub Desktop.
Save gre/1d3a2b164e7061475fc18df818a2a925 to your computer and use it in GitHub Desktop.
function recordHistory() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Toggle a cell that is used in one of a CRYPTOFINANCE formula to force-trigger a refresh
var r = ss.getSheetByName("folio").getRange("A30");
var unit = r.getValues()[0][0];
r.setValue(unit==='BTCEUR'?'BTC/EUR':'BTCEUR');
// accumulate history
var sheet = ss.getSheetByName("History");
var values;
for (var i=0; i<20; i++) { // try each second for 20 seconds
Utilities.sleep(1000);
var source = sheet.getRange("A2:G2");
values = source.getValues();
if (!isNaN(values[0][1])) { // if values is a number, we are done, otherwise it means we need to try again
break;
}
}
if (isNaN(values[0][1])) { // this was not successful and we must not append a row
return;
}
// append row to history
values[0][0] = new Date();
sheet.appendRow(values[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment