-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi calendar #9
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,15 @@ | |
// var targetCalendarName = "" // The name of the Google Calendar you want to add events to | ||
// var sourceCalendarURL = "" // The ics/ical url that you want to get events from | ||
|
||
var sourceCalendars={} | ||
|
||
var sourceCalendars={ | ||
CustomName:"ICS/ICAL URL" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than having |
||
|
||
|
||
// Currently global settings are applied to all sourceCalendars. | ||
|
||
var howFrequent = 15; //What interval (minutes) to run this script on to check for new events | ||
var howFrequent = 30; //What interval (minutes) to run this script on to check for new events | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this being changed again? Leftover from testing? |
||
var addEventsToCalendar = true; //If you turn this to "false", you can check the log (View > Logs) to make sure your events are being read correctly before turning this on | ||
var modifyExistingEvents = true; // If you turn this to "false", any event in the feed that was modified after being added to the calendar will not update | ||
var removeEventsFromCalendar = true; //If you turn this to "true", any event in the calendar not found in the feed will be removed. | ||
|
@@ -57,6 +60,17 @@ function Install(){ | |
|
||
function main(){ | ||
|
||
/* Some logic that tracks which calendar we left off on in the last execution could | ||
help reduce errors and redoing the same calendars if we include logic to detect maxing on quota or execution time */ | ||
|
||
for( var calendar in sourceCalendars){ | ||
Logger.log("Syncing "+ calendar); | ||
syncCalendar(calendar, sourceCalendars[calendar]); | ||
} | ||
} | ||
|
||
function syncCalendar(targetCalendarName, sourceCalendarURL) { | ||
|
||
//Get URL items | ||
var response = UrlFetchApp.fetch(sourceCalendarURL); | ||
response = response.getContentText().split("\r\n"); | ||
|
@@ -156,6 +170,7 @@ function main(){ | |
//---------------------------------------------------------------- | ||
|
||
if(addEventsToCalendar || removeEventsFromCalendar){ | ||
/* We might want to consider reducing how far back we reach for events to reduce API call usage... Also would make a good premium feature */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, but let's take this comment out so we don't have comments about "possible premium features" in our code :) |
||
var calendarEvents = targetCalendar.getEvents(new Date(2000,01,01), new Date( 2100,01,01 )) | ||
var calendarFids = [] | ||
for(var i=0; i<calendarEvents.length; i++){ | ||
|
@@ -207,13 +222,16 @@ function main(){ | |
|
||
var fe = fes[0]; | ||
|
||
if(e.getStartTime() != fe.startTime || e.getEndTime() != fe.endTime) | ||
/* Removing the checking reduces the API calls by 1/2 in this section and shouldn't | ||
Really cause any issues ( as far as i've seen in my own use ) - abrothers | ||
*/ | ||
//if(e.getStartTime() != fe.startTime || e.getEndTime() != fe.endTime) | ||
e.setTime(fe.startTime, fe.endTime) | ||
if(e.getTitle() != fe.title) | ||
//if(e.getTitle() != fe.title) | ||
e.setTitle(fe.title); | ||
if(e.getLocation() != fe.location) | ||
//if(e.getLocation() != fe.location) | ||
e.setLocation(fe.location) | ||
if(e.getDescription() != fe.description) | ||
//if(e.getDescription() != fe.description) | ||
e.setDescription(fe.description) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to deprecate
targetCalendarName
andsourceCalendarURL
, let's just remove those options