Coder Social home page Coder Social logo

gcal-cli's Introduction

gcal

Google Calendar command line tool for Node.js

Programmatic event listing, insert or bulk insert made easy:

  $ gcal insert 'Party tomorrow from 3pm to 5pm'

   Party: 2017-09-08T15:00:00+09:00 ~ 2017-09-08T17:00:00+09:00
   https://www.google.com/calendar/event?eid=amNpMWE5cjg2bG80n2s0Nmg1ZWlqcW01OXMgdG9rYWdlcm9oQG0
  $ echo \
  '[{
    "calendarId": "primary", "resource": {
    "summary": "Party",
    "start": { "dateTime": "2017-09-08T20:00" },
    "end": { "dateTime": "2017-09-08T22:00" }}
  },{
    "calendarId": "primary", "resource": {
    "summary": "Party again",
    "start": { "dateTime": "2017-09-08T22:00" },
    "end": { "dateTime": "2017-09-08T23:30" }}
  }]' \
  > events.json

  $ gcal bulk -e events.json

   Event inserted
    id: gif4hl86kgt7bmgq2ojvteqe2o
    summary: Party
    htmlLink: https://www.google.com/calendar/event?eid=Z2lmNGhsODZrZ3Q3Ym1ncTJvanZ0ZXFlMm8gdG9rYWdlcm9oQG0
   Event inserted
    id: blrrb8kbrih3pq9mn10slii8ac
    summary: Party again
    htmlLink: https://www.google.com/calendar/event?eid=YmxycmI4a2JyaWgzcHE5bW4xMHNsaWk4YWMgdG9rYWdlcm9oQG0
  $ gcal list

   Upcoming events (2017-09-07T00:00:00+09:00 ~ 2017-09-07T23:59:59+09:00)
    2017-09-07 20:00 - My favorite TV show
    2017-09-07 22:30 - Prepare tomorrow's meeting stuff

Installation

Install it as a global module:

npm install -g gcal

Authentication

Authorization and authentication is done with OAuth 2.0.

Ok, this will take only 2 minutes:

1) Get your project credentials

You will need a file with your credentials: client ID, client secret and redirect URI. This can be obtained in the Developer Console:

  • Go to your project
  • Click in Credentials
  • Click Create credentials โ†’ OAuth client ID ( Application type must be Other )
  • Download the JSON file

2) Generate consent page URL

Once we got the credentials we must generate a consent page URL.

$ gcal generateUrl

(By default the credentials will be searched in your home directory under the name client_secret.json).

The page will prompt you to authorize access, follow the instructions.

3) Get the token!

With the code we got through the authorization page, we can obtain a token and store it in our machine.

$ gcal storeToken <code>

(By default the token is stored in your home folder under the name calendar_api_token.json).

NOTE: The token will expiry after one hour, but a refresh_token is included as well, allowing the app to refresh automatically the token each time it's used.

With this we are good to go. The stored token and credentials files will be required from now on to use this tool.

Usage

List

List today events:

$ gcal list

List events using natural language (powered by Sherlock):

$ gcal list tomorrow
$ gcal list 'from 03/23/2017 to 03/27/2017'
$ gcal list 'from March 23th to 27th'

Or with specific ISO dates:

$ gcal list -f 2017-03-23 -t 2017-03-27

Insert

Insert events using natural language:

$ gcal insert 'Party tomorrow from 3pm to 5pm'

Insert events specifying the parameters:

$ gcal insert -s 'Party' -d 2017-03-23 -t 15:00 -D 2h

Bulk Insert

Bulk insert passing a .js or .json file:

events.json

[{
  "calendarId": "primary",
  "resource": {
    "summary": "Having coffee with Okuyasu",
    "location": "Morio City",
    "description": "I'm not very imaginative now so some description goes here",
    "start": {
      "dateTime": "2017-09-08T09:00:00"
    },
    "end": {
      "dateTime": "2017-09-08T10:00:00"
    }
  }
}, {
  "calendarId": "primary",
  "resource": {
    "summary": "Defeat Dio",
    "location": "179 Orouba St, Cairo",
    "description": "Dio is a bad boy so I need to kick his ass asap",
    "start": {
      "date": "1987-06-01"
    },
    "end": {
      "date": "1987-06-12"
    }
  }
}]
$ gcal bulk -e ./events.json

Using a .js file can be useful for relative dates and more:

events.js

const today = new Date();
today.setHours('17', '00', '00');
const tomorrow = new Date(today.getTime()+1000*60*60*24);
module.exports = [{
  "calendarId": "primary",
  "resource": {
    "summary": `Release`,
    "start": {
      "dateTime": today.toISOString()
    },
    "end": {
      "dateTime": today.toISOString()
    }
  }
}, {
  "calendarId": "primary",
  "resource": {
    "summary": "Release",
    "start": {
      "dateTime": tomorrow.toISOString()
    },
    "end": {
      "dateTime": tomorrow.toISOString()
    }
  }
}];
$ gcal bulk -e ./events.js

The available properties are listed here.

Overwriting default config

Using the option -C <file> the default config can be overwritten. This file must be .js or .json. Configurable options are located in ./conf.js.

Example:

/somepath/config.json

{
  "CRED_PATH": "/my/secret/path/credentials.json",
  "TOKEN_PATH": "/my/secret/path/token.json"
}
$ gcal -C /somepath/config.json generateUrl

Doing this you can store your credential files wherever you want.

API

Use the help command. More details will be added soon.

$ gcal help

Usage:
  gcal [-C <file>] [cmd] [--debug]

      OPTIONS
          -C, --config <file>
          --debug

Commands:

  list [<term> | [-f <date | datetime>] [-t <date | datetime>]] [-i]
      List events. By default it shows today events (executed without arguments).

      OPTIONS
          -f, --from <date | datetime>

          -t, --to <date | datetime>

          -i, --show-id


  insert <term> | -s <summary> -d <date> [-t <time>] [-D <duration>]
      Insert events. <term> is specified in natural language, in case it's not specified,
      -s and -d are mandatory.

      OPTIONS
          -s, --summary <summary>

          -d, --date <date>

          -t, --time <time>

          -D, --duration <duration>


  bulk -e <file>
      Bulk insert of events. File can be .json or .js.

      OPTIONS
          -e, --events <file>


  generateUrl
      Generate consent page URL. In order to work client_secret.js must be in your
      home folder.


  storeToken <code>
      Store Token in your home folder.


  help
      Show this help page.

About version 0.3.0

Version 0.3.0 used an immersive-cli instead of shell commands. If you want to use it, go to the branch 0.3.0.

License

MIT ยฉ Antonio V

gcal-cli's People

Contributors

andymule avatar dependabot[bot] avatar hasantayyar avatar toniov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gcal-cli's Issues

Support new credential types?

Hi there! I think Google has changed the types of Oauth2 credentials that can be generated in the dev console -- they no longer have the "Other" type. Any current guidance on how to generate the right credentials? Thanks!

Multiple Calendar Support

Hello,
Is it possible to use multiple calendars? I have a shared calendar among the family, in addition to my main one, and I would like to see all of them.

Thanks!

change time system from 12- to 24-hour clock

$ gcal insert 'interview Mon 11:00'

when I typed above, the result was "2020-08-24T23:00:00 ~ 2020-08-25T00:00:00", rather than "2020-08-24T11:00:00 ~ 2020-08-25T12:00:00" which I thought it would.

can we change this stuff? I think 24-hour time system is more intuitive than 11am or full qualified timestamp (ex, 2020-08-24T11:00:00)

storeToken results in an error

Have gone through token generation via URL generated by gcal generateUrl.
Code was successfully generated via this URL but storeToken delivers error:

(! 642)-> gcal -C /Users/ts/gcal/config.json storeToken [token]
[ERROR] invalid_grant

Resources (rooms) and clashes

Hi,

Would it be possible to implement the assignment of resources, e.g. a room when adding an entry to a calendar?

Would it also be possible to get a notification if there is a clash in the use of a resource when trying to add an entry to a calendar if there already is one?

error on generateUrl

Tried on Mac as described in readme.

Got

(ts)-(jobs:0)-(~)
(! 620)-> gcal --config /Users/ts/client_secret.json generateUrl
[ERROR] Cannot match against 'undefined' or 'null'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.