move ImportJson to lib, separate out RefreshData

This commit is contained in:
Collin M. Barrett 2017-01-10 08:51:15 -06:00
parent 3daa39eba1
commit 2736c225c0
2 changed files with 40 additions and 47 deletions

View file

@ -1,50 +1,3 @@
/*====================================================================================================================================*
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,noInherit");
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)

40
gs/type/RefreshData.gs Normal file
View file

@ -0,0 +1,40 @@
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,noInherit");
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)
}