-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendarEsp32.gs
87 lines (82 loc) · 2.03 KB
/
CalendarEsp32.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Calendar connection script
*/
function doGet(){
var now = new Date()
var nowInMS = now.getTime(); // 1562300592245
var add = 24 * 60 * 60 * 1000; // 43200000 = 24 hours in milliseconds
var dday;
var i = 0;
finalStr = "";
//Get next 6 days information
for (i=0; i<6; i++){
dday = nowInMS + (add * i)
finalStr += GetEvents(new Date(dday));
if(i!=5){
finalStr += "|\n"
}
}
Logger.log(finalStr);
return ContentService.createTextOutput(finalStr);
}
//Calendar Event Info getter
// - Name
// - Location
// - Start Time
// - End Time (or date) eg. tomorrow
// - All Day?? (no times needed)
// - Invitees
function GetEvents(date){
var _calendarName = 'CalendarEsp32' //Your Calendar Name in Google Calendar
var Cal = CalendarApp.getCalendarsByName(_calendarName)[0];
var Now = date;
var events = Cal.getEventsForDay(Now);
str = "";
finalStr = "";
finalStr += Now.toDateString() + "\n";
for (var i = 0; i < events.length; i++)
{
var allDay;
if(events[i].getStartTime().toLocaleTimeString().search("0:00:00") >= 0 &&
events[i].getEndTime().toLocaleTimeString().search("0:00:00") >= 0)
{
allDay = "allday";
}
else
{
allDay = "notday";
}
var guestList = events[i].getGuestList();
str += events[i].getTitle();
if(events[i].getLocation() != ""){
str += ", " + events[i].getLocation()
}
while(str.length < 36){
str += ' ' ;
}
if(allDay != "allday"){
str += events[i].getStartTime().toLocaleTimeString() + '-' ;
str += events[i].getEndTime().toLocaleTimeString() ;
}
else{
str += 'All day';
}
for (var j = 0; j < guestList.length; j++)
{
if(guestList[j].getName() != _calendarName)
{
if(guestList[j].getName() != "") {
str += guestList[j].getName() + ":" ;
}
else
{
str += guestList[j].getEmail() + ":" ;
}
}
}
//Remove last ":" from guest lists
finalStr += str + '\n';
str = "";
}
return finalStr;
}