Added HA integration script for my calendar to avoid all day events. Notes for G2.

This commit is contained in:
Norm Rasmussen
2023-08-21 20:38:44 -04:00
parent 84b6e51a40
commit b4ff268b5a
5 changed files with 142 additions and 1 deletions

View File

@ -0,0 +1,13 @@
* New Learning Paths
- G2 for Sales and Onboarding learning path to launch in October - mid-October is the most likely.
- The sales one will need to be re-written from the sellers POV.
- What is a seller? A customer like Northpass is a seller. A buyer will go to the NP page and read reviews.
- Sellers are G2 Customers.
- Should just be small edits to change the perspective.
- Question about LPs: She wants to know about two additional custom certs. Does she have to pay?
- "Everyone is talking about G2U" - internally its a buzz.
- Claims that there is no budget but may be able to wrangle a few bucks for the certs.
- New LPs will be pretty similar in content and structure as the previous.
- Will need to redo quizzes for the new learning paths
TODO: Submit ticket to transfer RTE elements: General, Resource, Course, Accordion

View File

@ -1,4 +1,4 @@
skuid = "84GO7zb7a990UJrnFJqiYcd0m"
skuid = "shdX7ht5PZHoOBKOZqZsTMaCJ"
unknown = "SlpQlju219WnWogn94dQUT6Yt"
forcemanager = "3ia7mWFkdeALYQFYoB51yh6Ov"
talkspace_core = "2vfHw6ksqGfT1gUhPM8pXx2wW"

View File

@ -0,0 +1 @@
{"scriptId":"169D4glCNoF91joR7OnS0RdqOb4Tpv8n-FbRRjCkfqjBtHv4Z75N_agFK","rootDir":"/Users/normrasmussen/Documents/Work/Scripts/GAS_GS/HomeAssistant_Calendar_Scrubber"}

View File

@ -0,0 +1,113 @@
var SOURCE_CALENDAR_ID = 'nrasmussen@gainsight.com'; // OR the full calendar id including @something.calendar.google.com
var SCRUBBED_CALENDAR_ID = 'c_9ad3baa9ffa4f385829b7618918d123d3b2c39a111a45d1d645b0e29d8fda68b@group.calendar.google.com';
var WEEKS_IN_ADVANCE = 1;
// The maximum script run time under Apps Script Pro is 30 minutes; this setting
// will be used to report when the script is about to reach that limit.
var MAX_PRO_RUNTIME_MS = 29 * 60 * 1000;
/**
* Look through the source calendar and copy all non-all-day events to the scrubbed calendar
*/
function syncCalendarAfterScrubbing() {
// Define the calendar event date range to search.
var today = new Date();
var futureDate = new Date();
futureDate.setDate(futureDate.getDate() + WEEKS_IN_ADVANCE*7);
var lastRun = PropertiesService.getScriptProperties().getProperty('lastRun');
lastRun = lastRun ? new Date(lastRun) : null;
if (isTimeUp(today, new Date())) {
Logger.log('Execution time about to hit quota limit; execution stopped.');
return;
}
// find events that are not all-day in the specified date range.
// Import each of those to the scrubbed calendar.
var count = 0;
var events = findEvents(SOURCE_CALENDAR_ID, today, futureDate, lastRun);
events.forEach(function(event) {
event.organizer = {
id: SCRUBBED_CALENDAR_ID
}
event.attendees = [];
Logger.log('Importing: %s', event.summary);
try {
Calendar.Events.import(event, SCRUBBED_CALENDAR_ID);
count++;
} catch (e) {
Logger.log(
'Error attempting to import event: %s. Skipping.', e.toString());
}
});
PropertiesService.getScriptProperties().setProperty('lastRun', today);
Logger.log('Imported ' + count + ' events');
var executionTime = ((new Date()).getTime() - today.getTime()) / 1000.0;
Logger.log('Total execution time (s) : ' + executionTime); ;
}
/**
* In a given calendar, look for non-all-day events
* in events within the specified date range and return any such events
* found.
* @param {string} cal_id the ID of the source calendar
* @param {Date} start the starting Date of the range to examine.
* @param {Date} end the ending Date of the range to examine.
* @param {Date} opt_since a Date indicating the last time this script was run.
* @return {object[]} an array of calendar event Objects.
*/
function findEvents(cal_id, start, end, opt_since) {
var params = {
timeMin: formatDate(start),
timeMax: formatDate(end),
showDeleted: true
};
if (opt_since) {
// This prevents the script from examining events that have not been
// modified since the specified date (that is, the last time the
// script was run).
params['updatedMin'] = formatDate(opt_since);
}
var results = [];
try {
var response = Calendar.Events.list(cal_id, params);
results = response.items.filter(function(item) {
// Filter out events where the the event is all-day
if (item.start.date) {
return false;
}
return true;
});
} catch (e) {
Logger.log('Error retriving events for %s; skipping',
e.toString());
results = [];
}
return results;
}
/**
* Return an RFC3339 formated date String corresponding to the given
* Date object.
* @param {Date} date a Date.
* @return {string} a formatted date string.
*/
function formatDate(date) {
return Utilities.formatDate(date, 'UTC', 'yyyy-MM-dd\'T\'HH:mm:ssZ');
}
/**
* Compares two Date objects and returns true if the difference
* between them is more than the maximum specified run time.
*
* @param {Date} start the first Date object.
* @param {Date} now the (later) Date object.
* @return {boolean} true if the time difference is greater than
* MAX_PROP_RUNTIME_MS (in milliseconds).
*/
function isTimeUp(start, now) {
return now.getTime() - start.getTime() > MAX_PRO_RUNTIME_MS;
}

View File

@ -0,0 +1,14 @@
{
"timeZone": "America/New_York",
"dependencies": {
"enabledAdvancedServices": [
{
"userSymbol": "Calendar",
"version": "v3",
"serviceId": "calendar"
}
]
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}