Emacs Calendar Extension – Information Unity (Part 2)

0

Go back to the first post in this series, I was trying to solve the problem of having many views of my calendars, but only a single source of record. Specifically, I wanted to be able to view this “source” calendar in Emacs without the manual syncing process.

As was discussed earlier, a few of the issues were solved:

  1. Google Calendar exports calendars in the iCalendar format
  2. Emacs Calendar is able to import an iCalendar format file via URL

Stellar! This is going to be easy! I’ll just list out my calendars’ iCalendar URLs (provided by Google), and have Emacs Calendar cycle through them and import them. Nice 🙂

First, let’s create a var that points to our diary file (that way we can export it to our site config if necessary)

1
(setq diary-file (concat my-emacs-org "diary_entries"))

Next, I’ll create an alist  to hold all my calendars.

1
2
3
(setq my-ical-calendars-alist '(
 ("test", "https://www.google.com/calendar/icaltest.ics")
 ))

All nice and easy thus far. The next thing we need to do is write a nifty function to help import the URL as icalender.el can only import from a file via icalendar-import-file.

No problem, as there’s a built-in function to download a URL to a local temp copy – url-file-local-copy.

We’ll write our function to:

  1. Download the URL
  2. Pass the temp file to icalendar-import-file
  3. Close the buffer
1
2
3
4
5
6
7
(defun import-remote-ical (url my-diary-file)
 "Download ics file from URL and add to diary"
 (let ((tmpfile (url-file-local-copy url)))
 (icalendar-import-file tmpfile my-diary-file nil)
 (kill-buffer (car (last (split-string tmpfile "/"))))
 )
)

I run it and am astounded that it works! So I run it a few more times to make sure I’m not imagining things. Yup – it does work!

I hurriedly open my diary file, anxious to see my handiwork and… (wait for it) … uggh. There are multiple duplicates for each event. I should’ve known that it couldn’t of been that easy.

Read more

Tags: , , ,