Giter VIP home page Giter VIP logo

gcal-to-org's Introduction

Export google calendar to org-mode

Overview

A simple little CLI tool to export your google calendar into org-mode.

Unlike the synchronization workflow described on the on the Worg website, gcal-to-org uses Google's API Client Library for Java. Since it authenticates using OAUTH, there is no need to make your calendar publicly available through a "hidden" url.

This tool is in the early stages and narrowly focused on my particular needs. However, it should be easy to adapt it to your use-case, and I would be happy to iterate on the design.

Installation

npm install -g gcal-to-org

Usage

First create a config.edn config file somwhere. Below is a minimal example for a single calendar. See config.example.edn for a fully commented example.

{:calendars [{:id "[email protected]"}]
 ;; Google API credentials (see below)
 :client-id "123456789-abcdedfhijklmopqrst0123.apps.googleusercontent.com"
 :client-secret "qDcAHZyjdEDikPtIaaElOyF9"}

Then run just run the CLI tool to print org-mode text to stdout.

gcal-to-org path/to/config.edn

On the first run, it will open an OAUTH window in your default browser and cache your OAUTH tokens to disk. On subsequent runs, it simply uses the cached credentials and behaves like any other CLI tool.

Obtaining Google API credentials

You need to register gcal-to-org as an application yourself to obtain a Client ID and Client secret.

Go to the Google API Manager and create a new project under any name.

Within that project, enable the "Calendar" API. There should be a searchbox where you can just enter those terms.

In the sidebar, select "Credentials" and then create a new "OAuth Client ID". The application type is "Other".

You’ll be prompted to create a OAuth consent screen first. Fill out that form however you like.

Finally you should have a Client ID and a Client secret. Provide these in the config below.

Emacs integration

Everyone's setup is different, but in case you are interested, here is how I call the tool from emacs.

;;; Write work agenda here
(defvar my-work-agenda-file "~/var/work.org")

;;; Add work agenda to default agenda files
(add-to-list 'org-agenda-files my-work-agenda-file)

(defun my-update-work-agenda-file ()
  "Create work agenda file by pulling from Google Calendar."
  (if (zerop (call-process "gcal-to-org" nil `(:file ,my-work-agenda-file) nil "/path/to/config.edn"))
      (let ((buf (find-buffer-visiting my-work-agenda-file)))
        ;; Revert work buffer if it exists
        (when buf
          (with-current-buffer buf
            (revert-buffer nil t)))
        (message "Successfully updated %s" my-work-agenda-file))
    (message "Failed to update %s" my-work-agenda-file)))

;;; Add command to call gcal-to-org from the agenda dispatch view. Bound to "w" key.
(add-to-list 'org-agenda-custom-commands
             '("w" "Update work agenda file"
               ;; This functions gets called with a match object that we discard.
               (lambda (_) (my-update-work-agenda-file)))
             t)

gcal-to-org's People

Contributors

jwhitbeck avatar dwoos avatar

Stargazers

sam bacha avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

dwoos

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.