refresh data on-demand

By refreshing the data manually from the Google Sheets menu, Google Sheets loading errors should be avoided when WordPress tries to update it's data nightly.
This commit is contained in:
Collin M. Barrett 2017-01-09 09:26:38 -06:00 committed by GitHub
parent bf1b141c87
commit ab51b7ea10

View file

@ -1,5 +1,51 @@
// forked from https://github.com/fastfedora/google-docs
/*====================================================================================================================================*
run ImportJSON on-demand from Sheets menu
====================================================================================================================================*/
var typeSheet = {
"FilterLists Global": "GlobalData",
"FilterLists Regional": "RegionalData",
"FilterLists Forked": "ForkedData",
"FilterLists Combo": "ComboData",
"FilterLists Stale": "StaleData"
};
var typeGitHubUrl = {
"FilterLists Global": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/global.json",
"FilterLists Regional": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/regional.json",
"FilterLists Forked": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/forked.json",
"FilterLists Combo": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/combo.json",
"FilterLists Stale": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/stale.json"
};
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet(),
options = [{
name: "Refresh Data",
functionName: "refreshJson"
}, ];
ss.addMenu("Refresh Data", options);
}
function refreshJson() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(typeSheet[ss.getName()]);
var data = ImportJSON(typeGitHubUrl[ss.getName()], "", "noTruncate,rawHeaders");
for (i = 0; i < data.length; i++) {
for (j = 0; j < data[0].length; j++) {
if (data[i][j] == null) {
data[i][j] = "";
}
}
}
sheet.clearContents();
var range = sheet.getRange(1, 1, data.length, data[0].length);
range.setValues(data)
}
// forked from https://github.com/fastfedora/google-docs
/*====================================================================================================================================*
ImportJSON by Trevor Lohrbeer (@FastFedora)
====================================================================================================================================
@ -532,4 +578,4 @@ function convertToBool_(map, key) {
if (map[key] != null) {
map[key] = toBool_(map[key]);
}
}
}