Skip to content

misohena/gcal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

111 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Calendar Utilities for Emacs

Settings on Google server

  1. Access Google Cloud Console ( https://console.cloud.google.com/cloud-resource-manager ).
  2. Create a Project.
  3. Enable Google Calendar API.
  4. Create a OAuth Client ID (Choose “Desktop” type and Download client ID and client secret).
  5. Change publishing status to “In production” in OAuth Consent Screen.

gcal.el

Settings:

;; Get from Google Developer Console
(setq gcal-client-id "xxxxxxxxx.apps.googleusercontent.com")
(setq gcal-client-secret "xxxx-XxxxXxxXXXxx") ;;API-KEY

Usege:

(require 'gcal)

;; list my calendars
(gcal-calendar-list-list) ;; Calendar List

;; list events
(gcal-events-list
 "example@group.calendar.google.com" ;; Calendar ID
  `((timeMin . ,(gcal-datetime 2016 5 1))
    (timeMax . ,(gcal-datetime 2016 6 1))))

;; insert event
(gcal-events-insert
 "example@group.calendar.google.com"
 `((start . ,(gcal-gtime 2016 5 27))
   (end . ,(gcal-gtime 2016 5 28))
  (summary . "My Special Holiday")))

;; delete event
(gcal-events-delete "example@group.calendar.google.com" "{event id}")

gcal-org.el

Usage:

(require 'gcal-org)

;; Org to Google Calendar

(gcal-org-push-file
 "example@group.calendar.google.com" ;; Calendar ID
 "~/my-schedule.org" ;; Org file
 "~/my-schedule.gcal-cache") ;; Cache file (If omitted, use the global cache file ~/.emacs.d/.gcal-org-pushed-events)

;; Google Calendar to Org

(gcal-org-pull-to-file
 "example@group.calendar.google.com"
 "~/my-schedule.org"
 "Inbox"
 "~/my-schedule.gcal-cache")

Parse org & Upload

;; Org to oevent(org-mode event)
(gcal-org-parse-buffer) ;; Parse current buffer. Return a list of gcal-org-event object(including properties :id, :ord, :summary, :location, :ts-start, :ts-end, :ts-prefx, ...).

(gcal-org-parse-file "~/my-schedule.org") ;; Parse specified org file.

;; Upload oevents to Google Calendar
(gcal-org-push-oevents
  "example@group.calendar.google.com"
  (gcal-org-parse-file "~/my-schedule.org")
  nil)

;; Upload oevents to Google Calendar (delta)
(gcal-org-push-oevents
  "example@group.calendar.google.com"
  (gcal-org-parse-file "~/my-schedule.org")
  (gcal-org-parse-file "~/my-schedule.org.old"))

;; Delete events from Google Calendar
(gcal-org-push-oevents
  "example@group.calendar.google.com"
  nil
  (gcal-org-parse-file "~/my-schedule.org"))

Download

;; Download oevents from Goole Calendar
(gcal-org-pull-oevents
 "example@group.calendar.google.com"
 `((timeMin . ,(gcal-time-format (current-time) nil)))) ;;after current time

Asynchronous execution

(gcal-http-async ;; or -sync
 (gcal-async-let ((calendars (gcal-calendar-list-list)))
   (message "number of items: %s" (length (alist-get 'items calendars)))))
(gcal-http-async
 (gcal-async-let* ((calendars (gcal-calendar-list-list)) ;; If you call an async function, it must be the last in the expression.
                   (calendar-id (alist-get 'id (elt (alist-get 'items calendars)
                                                    5))) ;; It is also possible to not include async functions.
                   (events (gcal-events-list calendar-id
                                             `((timeMin . ,(gcal-datetime 2024 2 1))
                                               (timeMax . ,(gcal-datetime 2024 3 1))))))
   (message "events=%s" events)))
(gcal-http-async
 (let ((event-list .....)
       (calendar-id ".......")
       response-list)
   (gcal-async-wait-all
       ;; Inside this, multiple asynchronous functions are executed.
       (dolist (event-data event-list)
         (gcal-async-let ((response (gcal-events-insert calendar-id event-data)))
           (push response response-list)))
     ;; Called when everything is complete.
     (if (seq-some #'gcal-failed-p response-list)
         (message "Looks like something went wrong.")
       (message "It seems to have finished without any problems.")))))

Documents

Releases

No releases published

Packages

 
 
 

Contributors