Created
December 23, 2017 09:12
-
-
Save gre/1d3a2b164e7061475fc18df818a2a925 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
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