From ab51b7ea10905442221358fd0a727efafb521bee Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Mon, 9 Jan 2017 09:26:38 -0600 Subject: [PATCH] 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. --- gs/type/{ImportJSON.gs => ImportJson.gs} | 50 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) rename gs/type/{ImportJSON.gs => ImportJson.gs} (92%) diff --git a/gs/type/ImportJSON.gs b/gs/type/ImportJson.gs similarity index 92% rename from gs/type/ImportJSON.gs rename to gs/type/ImportJson.gs index 5553b7581..1f47ada7b 100644 --- a/gs/type/ImportJSON.gs +++ b/gs/type/ImportJson.gs @@ -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]); } -} \ No newline at end of file +}