-
Notifications
You must be signed in to change notification settings - Fork 4
make google sheet from calendar #73
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
Open
dckc
wants to merge
11
commits into
cosmosAPI
Choose a base branch
from
cal-to-sheet
base: cosmosAPI
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aacb798
feat: google sheet made from calendars (WIP)
dckc 4cedb1b
build(cal-to-sheet): save pull/push scripts
dckc 52fea7d
refactor(cal-to-sheet): onOpen was moved to menu.js
dckc 329188c
chore(cal-to-sheet): NonNullish, die utilities
dckc 188e47e
chore: fix event.getHtmlLink() hallucination
dckc c6b924d
chore: punt success notice
dckc d6492d0
chore: clear condition is rows in sheet, not rows in data
dckc eac816b
chore: use active sheet; hoist io so caller can inject
dckc 7335fcf
chore: hoist getUi I/O
dckc 7800dc4
build(cal-to-sheet): add to workspace
dckc b5662f1
fixup! feat: google sheet made from calendars (WIP)
dckc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "timeZone": "America/Chicago", | ||
| "dependencies": { | ||
| }, | ||
| "exceptionLogging": "STACKDRIVER", | ||
| "runtimeVersion": "V8" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| const die = msg => { | ||
| throw Error(msg); | ||
| }; | ||
| const NonNullish = (x, msg) => x || die(msg); | ||
|
|
||
| function getCalendarEventUrl(calendarId, eventId) { | ||
| return `https://calendar.google.com/calendar/event?cid=${calendarId}&eid=${eventId}`; | ||
| } | ||
|
|
||
| /** | ||
| * Updates the spreadsheet with events from the specified Google Calendar. | ||
| */ | ||
| function updateSheetFromCalendar(_nonce, io = {}) { | ||
| const { | ||
| // Get the spreadsheet and sheet | ||
| ss = SpreadsheetApp.getActiveSpreadsheet(), | ||
| sheet = ss.getActiveSheet() || ss.getSheets()[0], | ||
| sheetName = sheet.getName(), | ||
| // Get the calendar | ||
| calendar = NonNullish( | ||
| CalendarApp.getCalendarsByName(sheetName), | ||
| `cannot find calendar ${sheetName}`, | ||
| )[0], | ||
| // Get today's date (for the start of the query) | ||
| today = new Date(), | ||
| ui = SpreadsheetApp.getUi(), | ||
| } = io; | ||
|
|
||
| const calendarId = calendar.getId(); | ||
|
|
||
| const firstRow = 1; // The first row to write data to (header row assumed above) | ||
| const clearExistingData = true; // Set to true to clear existing data before updating | ||
|
|
||
| today.setHours(0, 0, 0, 0); // Start of the day | ||
|
|
||
| // Get events from the calendar (you can adjust the date range as needed) | ||
| const events = calendar.getEvents( | ||
| today, | ||
| new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000), | ||
| ); // Events for the next year | ||
|
|
||
| // Prepare data for the sheet | ||
| const eventData = events.map(event => [ | ||
| event.getTitle(), | ||
| event.getStartTime(), | ||
| event.getEndTime(), | ||
| event.getLocation(), | ||
| event.getDescription(), | ||
| getCalendarEventUrl(calendarId, event.getId()), | ||
| ]); | ||
|
|
||
| // Clear existing data if specified | ||
| if (clearExistingData && sheet.getLastRow() > 0) { | ||
| sheet | ||
| .getRange(firstRow, 1, sheet.getLastRow(), sheet.getLastColumn()) | ||
| .clearContent(); | ||
| } | ||
|
|
||
| // Write the event data to the sheet | ||
| if (eventData.length > 0) { | ||
| sheet | ||
| .getRange(firstRow, 1, eventData.length, eventData[0].length) | ||
| .setValues(eventData); | ||
|
|
||
| // Add headers if the sheet was empty or cleared | ||
| if (clearExistingData || sheet.getLastRow() === 0) { | ||
| sheet.insertRowBefore(firstRow); | ||
| sheet | ||
| .getRange(firstRow, 1, 1, 6) | ||
| .setValues([ | ||
| [ | ||
| 'Title', | ||
| 'Start Time', | ||
| 'End Time', | ||
| 'Location', | ||
| 'Description', | ||
| 'Calendar Link', | ||
| ], | ||
| ]); | ||
| sheet.getRange(firstRow, 1, 1, 6).setFontWeight('bold'); | ||
| } | ||
| } else { | ||
| ui.alert( | ||
| 'Info', | ||
| 'No events found in the specified calendar for the given date range.', | ||
| SpreadsheetApp.Ui.ButtonSet.OK, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /** | ||
| * Adds a custom menu to the spreadsheet. | ||
| */ | ||
| function onOpen() { | ||
| SpreadsheetApp.getUi() | ||
| .createMenu('Calendar Sync') | ||
| .addItem('Update from Calendar', 'updateSheetFromCalendar') | ||
| .addToUi(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "scripts": { | ||
| "pull": "clasp pull", | ||
| "push": "clasp push" | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd rather get all the events, past or future, but only 1 for repeating events. Like a .ics export.