0.0.6 • Published 1 year ago

gsheet-to-calendar v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

MethodStatus
GoogleOnly with access_token or by integrating with valid google oauth api credentials⚠️
ICSFully supported
JSONFully supported
TerminalFully supported

CLI usage

# Run
$ gsToCalendar
PropsDescriptionRequiredDefault
sheetIdGoogle sheet id from current documentfalsenull
optionsOptions objectfalsenull
options.debugEnable error loggingfalsefalse
options.docIdDefines the google document idfalsenull
options.sheetIdDefines the google sheet idfalsenull
options.dateFormatDefines the date string format.Follow date-fns parse documentationfalse"d 'de' MMMM"
options.dateStringColumnDefines wich column contains the date stringfalsenull
options.titleStringColumnDefines wich column contains the event title stringfalsenull
options.localeDefines the locale for the date-fns. (ISO 639-1)falseptBR
options.startColumnDefine the initial columnfalseA

Usage as a package

Install the package using your favorite package manager.

$ npm i gsheet-to-calendar

Add the following enviroment variable:

// .env
// https://developers.google.com/sheets

DOC_API_KEY= Your google spreadsheet api key

Example snippet

Here's a basic usage of the package.

// yourApiRoute.ts

import { 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()

PropsDescriptionRequired
urlGoogle spreadsheet document urltrue
// 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.

PropsDescriptionRequiredDefault
sheetIdGoogle sheet id from current documentfalsenull
optionsOptions objectfalsenull
options.debugEnable error loggingfalsefalse
options.docIdDefines the google document idfalsenull
options.sheetIdDefines the google sheet idfalsenull
options.dateFormatDefines the date string format.Follow date-fns parse documentationfalse"d 'de' MMMM"
options.dateStringColumnDefines wich column contains the date stringfalsenull
options.titleStringColumnDefines wich column contains the event title stringfalsenull
options.localeDefines the locale for the date-fns. (ISO 639-1)falseptBR
options.startColumnDefine the initial columnfalseA
// Return of fetch events()

events: EventTypes[];
saveToGoogle: (accessToken: string) => Promise<void>;
calendarTitle: string;

EventTypes

interface EventTypes {
  date: Date;
  title: string;
}

saveToGoogle()

Save events to google calendar.

PropsDescriptionRequired
accessTokenGoogle OAuth access_tokentrue

Standalone functions

You can also import each function and execute it directly anytime.

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);