Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DeepInThought/47156db696238ae747a60b1fc342152d to your computer and use it in GitHub Desktop.
Save DeepInThought/47156db696238ae747a60b1fc342152d to your computer and use it in GitHub Desktop.
Google Script Cache-Bursting
// Set your variables below
SHEET_NAME="MC-Import-Data"
URL="https://coinmarketcap.com/currencies/views/all/"

// Create a trigger to refresh every 5 minutes
function myFunctionA() {
  ScriptApp.newTrigger("getData")
  .timeBased()
  .everyMinutes(5)
  .create();
}

// Create a trigger to refresh every time the sheet is reopened 
function myFunctionB() {
  ScriptApp.newTrigger("getData")
  .fromSpreadsheet()
  .open()
  .create();
}

// Compile your variable URL with an appended data-time stamp
function getData() {
  SpreadsheetApp
  .getActiveSpreadsheet()
  .getSheetByName(SHEET_NAME)
  .getRange("A1")
  .setValue( URL + "?" + Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss") );
}

// Upon completion, you will get an updating URL in A1 of the sheet you specified in the URL= variable
// Be sure to open your sheet and use the updating URL to build your IMPORTHTML formula
// Example: =IMPORTHTML(A1,"TABLE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment