Files
OpenEPaperLink/ESP32_AP-Flasher/data/calendar.txt
Nic Limper e19c9dc612 added content: google calendar
via google apps script, see /data/calendar.txt
2023-03-23 23:40:06 +01:00

47 lines
1.9 KiB
Plaintext

To use Google Apps Script to get all events for the next day and return them via JSON in a web app, you can follow these steps:
Create a new Google Apps Script project by going to https://script.google.com and clicking on "New project".
In the script editor, create a new function called "getEventsForNextDay" that will fetch all events for the next day and return them in JSON format:
function getEventsForNextDay() {
var start = new Date();
var end = new Date();
end.setDate(end.getDate() + 1);
var calendars = CalendarApp.getAllCalendars();
var events = [];
for (var i = 0; i < calendars.length; i++) {
var calendar = calendars[i];
var eventsInCalendar = calendar.getEvents(start, end);
for (var j = 0; j < eventsInCalendar.length; j++) {
var event = eventsInCalendar[j];
events.push({
title: event.getTitle(),
start: Math.floor(event.getStartTime().getTime() / 1000),
end: Math.floor(event.getEndTime().getTime() / 1000),
location: event.getLocation(),
description: event.getDescription()
});
}
}
// Sort events by start date/time
events.sort(function(a, b) {
return a.start - b.start;
});
return JSON.stringify(events);
}
function doGet() {
var content = getEventsForNextDay();
var output = ContentService.createTextOutput(content);
output.setMimeType(ContentService.MimeType.JSON);
return output;
}
This function calls the getEventsForNextDay() function to get the events in JSON format, creates a text output with the JSON content, sets the MIME type to JSON, and returns the output.
Deploy the web app by clicking on "Deploy > New Deployment" in the script editor. Choose "Web app" as the deployment type, set the access to "Anyone, even anonymous", and click on "Deploy". Make sure to take note of the web app URL generated by Google.
Test the web app by visiting the web app URL in a web browser. You should see the events for the next day in JSON format.