From 87a5ea75b93908aaf3737bd86c26467de15cdac6 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 21 Sep 2019 17:50:12 -0400 Subject: [PATCH 1/2] Save sheet ID to script properties --- sheetScript.gs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sheetScript.gs b/sheetScript.gs index f5265dd..5430c0f 100644 --- a/sheetScript.gs +++ b/sheetScript.gs @@ -6,9 +6,7 @@ function doGet(e) { - // url = https://docs.google.com/spreadsheets/d/XXXXXXXXXX/edit#gid=0 - var sheetID = 'XXXXXXXXXX'; // Paste the Sheet ID here, it's the long string in the Sheet URL - + var sheetID = PropertiesService.getScriptProperties().getProperty("sheetID"); if (e.parameter.update == "True") { var sheet = SpreadsheetApp.openById(sheetID).getSheets()[0]; updatePlaylists(sheet); @@ -21,8 +19,10 @@ function doGet(e) { } function updatePlaylists(sheet) { - if (!sheet || !sheet.toString || sheet.toString() != 'Sheet') sheet = SpreadsheetApp.openById('XXXXXXXXXX').getSheets()[0]; // Hotfix, Paste the Sheet ID here, it's the long string in the Sheet URL - var MILLIS_PER_DAY = 1000 * 60 * 60 * 24; + var sheetID = PropertiesService.getScriptProperties().getProperty("sheetID") + if (!sheetID) onOpen() + if (!sheet || !sheet.toString || sheet.toString() != 'Sheet') sheet = SpreadsheetApp.openById(sheetId).getSheets()[0]; + const MILLIS_PER_DAY = 1000 * 60 * 60 * 24; var data = sheet.getDataRange().getValues(); var reservedTableRows = 3; // Start of the range of the PlaylistID+ChannelID data var reservedTableColumns = 2; // Start of the range of the ChannelID data @@ -67,7 +67,7 @@ function updatePlaylists(sheet) { else channelIds.push(channel); } - + /// ...get videos from the channels... var videoIds = []; var lastTimestamp = sheet.getRange(reservedTimestampCell).getValue(); @@ -319,6 +319,10 @@ function ISODateString(d) { // modified from src: http://stackoverflow.com/quest function onOpen() { SpreadsheetApp.getActiveSpreadsheet().addMenu("Functions", [{name: "Update Playlists", functionName: "insideUpdate"}]); + var ss = SpreadsheetApp.getActiveSpreadsheet() + var sheet = ss.getSheets()[0] + if (!sheet || sheet.getRange("A3").getValue() !== "Playlist ID") throw new Error("Cannot find playlist sheet, make sure the sheet with playlist IDs and channels is the first sheet (leftmost)") + PropertiesService.getScriptProperties().setProperty("sheetID", ss.getId()) } function insideUpdate(){ From b85e927d1aa4bad2a7628483ff1609c779ee6723 Mon Sep 17 00:00:00 2001 From: dudemario Date: Sun, 22 Sep 2019 15:22:09 -0400 Subject: [PATCH 2/2] Remove excess spacing --- sheetScript.gs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheetScript.gs b/sheetScript.gs index 5430c0f..42355e6 100644 --- a/sheetScript.gs +++ b/sheetScript.gs @@ -67,7 +67,7 @@ function updatePlaylists(sheet) { else channelIds.push(channel); } - + /// ...get videos from the channels... var videoIds = []; var lastTimestamp = sheet.getRange(reservedTimestampCell).getValue();