Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
// var targetCalendarName = "" // The name of the Google Calendar you want to add events to
Copy link
Owner

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 and sourceCalendarURL, let's just remove those options

// var sourceCalendarURL = "" // The ics/ical url that you want to get events from

var sourceCalendars={}

var sourceCalendars={
CustomName:"ICS/ICAL URL"
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than having sourceCalendars "prepopulated" with example data, let's leave it blank (like you did before with var sourceCalendars = { }; ) and put a comment before explaining how it should be used (even use a block comment if you need to)



// 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
Copy link
Owner

Choose a reason for hiding this comment

The 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.
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 */
Copy link
Owner

Choose a reason for hiding this comment

The 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++){
Expand Down Expand Up @@ -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)


Expand Down