https://github.com/makis-san/gsheet-to-calendar
CLI app and package that uses google spreadsheet api to export calendar data directly into google agenda or other supported methods :)
https://github.com/makis-san/gsheet-to-calendar
calendar cli google googlespreadsheet
Last synced: 4 months ago
JSON representation
CLI app and package that uses google spreadsheet api to export calendar data directly into google agenda or other supported methods :)
- Host: GitHub
- URL: https://github.com/makis-san/gsheet-to-calendar
- Owner: makis-san
- License: mit
- Created: 2023-02-11T01:18:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-21T03:32:29.000Z (over 2 years ago)
- Last Synced: 2025-02-01T14:51:12.489Z (5 months ago)
- Topics: calendar, cli, google, googlespreadsheet
- Language: TypeScript
- Homepage: https://sheet2calendar.santiagosouza.dev/
- Size: 18.3 MB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
![]()
Google Spreadsheet to Calendar
CLI app and package that uses google spreadsheet api to export calendar data directly into google agenda or other supported methods :)
## Planned releases
- Web application (Working on)
- Publish to homebrew## Supported exports
| Method | Status | |
| -------- | -------------------------------------------------------------------------------- | --- |
| Google | Only with access_token or by integrating with valid google oauth api credentials | ⚠️ |
| ICS | Fully supported | ✅ |
| JSON | Fully supported | ✅ |
| Terminal | Fully supported | ✅ |## CLI usage
```sh
# Run
$ gsToCalendar
```| Props | Description | Required | Default |
| ------------------------- | ------------------------------------------------------------------------------------------------------------- | -------- | ------------- |
| sheetId | Google sheet id from current document | false | null |
| options | Options object | false | null |
| options.debug | Enable error logging | false | false |
| options.docId | Defines the google document id | false | null |
| options.sheetId | Defines the google sheet id | false | null |
| options.dateFormat | Defines the date string format.Follow [date-fns parse documentation](https://date-fns.org/v2.29.3/docs/parse) | false | "d 'de' MMMM" |
| options.dateStringColumn | Defines wich column contains the date string | false | null |
| options.titleStringColumn | Defines wich column contains the event title string | false | null |
| options.locale | Defines the locale for the date-fns. (ISO 639-1) | false | ptBR |
| options.startColumn | Define the initial column | false | A |## Usage as a package
Install the package using your favorite package manager.
```shell
$ npm i gsheet-to-calendar
```Add the following enviroment variable:
```ts
// .env
// https://developers.google.com/sheetsDOC_API_KEY= Your google spreadsheet api key
```### Example snippet
Here's a basic usage of the package.
```ts
// yourApiRoute.tsimport { loadSheetDocument } from 'gsheet-to-calendar';
export const handle = async (documentUrl: string) => {
const data = await loadSheetDocument({
url: documentUrl
});if (!document) return;
const events = await data.fetchEvents();
if (!events) return;
return events.saveToGoogle(body.token as string);
};
```### loadSheetDocument()
| Props | Description | Required |
| ----- | ------------------------------- | -------- |
| url | Google spreadsheet document url | true |```ts
// Return of loadSheetDocument()document: GoogleSpreadsheet; // Read more at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets#spreadsheetproperties
sheetList: [{
value: string;
name: string;
}, ...]
fetchEvents: () => Promise<{...}>;
```### fetchEvents()
Fetch events from the spreadsheet and return.
| Props | Description | Required | Default |
| ------------------------- | ------------------------------------------------------------------------------------------------------------- | -------- | ------------- |
| sheetId | Google sheet id from current document | false | null |
| options | Options object | false | null |
| options.debug | Enable error logging | false | false |
| options.docId | Defines the google document id | false | null |
| options.sheetId | Defines the google sheet id | false | null |
| options.dateFormat | Defines the date string format.Follow [date-fns parse documentation](https://date-fns.org/v2.29.3/docs/parse) | false | "d 'de' MMMM" |
| options.dateStringColumn | Defines wich column contains the date string | false | null |
| options.titleStringColumn | Defines wich column contains the event title string | false | null |
| options.locale | Defines the locale for the date-fns. (ISO 639-1) | false | ptBR |
| options.startColumn | Define the initial column | false | A |```ts
// Return of fetch events()events: EventTypes[];
saveToGoogle: (accessToken: string) => Promise;
calendarTitle: string;
```### EventTypes
```ts
interface EventTypes {
date: Date;
title: string;
}
```### saveToGoogle()
Save events to google calendar.
| Props | Description | Required |
| ----------- | ------------------------- | -------- |
| accessToken | Google OAuth access_token | true |## Standalone functions
You can also import each function and execute it directly anytime.
```ts
import { fetchEvents, googleSheet, saveToGoogle } from 'gsheet-to-calendar';fetchEvents(document, {
sheetId,
options: {
dateFormat,
locale,
startColumn,
dateStringColumn,
debug,
titleStringColumn
}
});googleSheet.loadDocument(url, (error) => console.log(error));
googleSheet.getSheets(document);saveToGoogle(calendarTitle, events, accessToken);
```