Hi, all!

It's been a while since I had this idea on my mind, but only now could I find
the time to make it real. I wanted to have a single set of calendar entries in
planner, Google calendar, my smartphone, etc. So, the easiest way, so far, is
to export my planner entries into an ical format. Initially I thought I would
use planner-icalendar.el, but this is not enough, as I use my today plan page
with all my tasks. What I need is my cyclic entries to appear on the calendar,
and my appointments made for a given day / hour - just like what I've
accomplished earlier with my hacks to weekly-view.

After having the export done, the only thing I'm lacking is a way to import an
ical. I don't want to import it to the main diary file, but to a temporary one,
so I can do a weekly-view, or see the calendar based on it - then discard it,
if I don't need it. It seems we're evolving towards multiple, possibly shared,
calendars, so I believe this should be on everyone's wishlist. Is anyone
handling this situation already? How?


So here's the code, you should set it up after having the mentioned hacks to
weekly-view, as I have redifined some functions. All you need then is to find a
good destination (e.g., a remote location), and call `planner-export-ical'. See
the thread at
http://www.archivum.info/[email protected]/2006-03/msg00112.html
for details on the required adaptations.

;; iCalendar export of appointments:

(load "icalendar.el")

(defun planner-export-ical (category-regexp n ical-output-file)
  "Write ICAL-OUTPUT-FILE with iCalendar format. CATEGORY_REGEXP will
limit category marked entries, enabling filtering of the exported
data (up until N days from now).
The iCalendar exported data are all the planner task appointments and
all the cyclic diary entries (in `planner-cyclic-diary-file').
They are exported as VEVENTs."
  (interactive)
  ;; Get the appointments until end-date:
  (let ((appts (planner-appt-forthcoming-get-appts n (planner-today))))
    ;; And now add the cyclic appointments from the appropriate file:
    (with-temp-buffer
      (let ((cyclic-appts nil))
        (with-temp-buffer
          (find-file planner-cyclic-diary-file)
          (dolist (line (split-string (buffer-string) "[\n\r]"))
            (unless (or (string= line "")
                        (string-match "^!" line))
              (push line cyclic-appts)))
          (kill-buffer (current-buffer)))
        (dolist (appt-desc cyclic-appts)
          (let ((appt-category (when (string-match "\\(.*\\)[ \t]*(\\(.*\\))$" 
appt-desc)
                                 (match-string 2 appt-desc)))
                (appt-text (match-string 1 appt-desc)))
            ;; Now filter by categories regexp:
            (when (string-match category-regexp appt-category)
              (when (string-match "\\(.*\\) @\\([0-2]?[0-9]:[0-5]?[0-9]\\)[ 
\t]*[-|][ \t]*\\([0-2]?[0-9]:[0-5]?[0-9]\\)[ \t]*|?[ \t]*\\(.*\\)$"
                                  appt-text)
                (let ((day        (match-string 1 appt-text))
                      (start-time (match-string 2 appt-text))
                      (end-time   (match-string 3 appt-text))
                      (text       (match-string 4 appt-text)))
                  (setq appt-text (format "%s %s-%s %s\n" day start-time 
end-time text))
                  (message "Adding cyclic appt to temp diary:::: %s" appt-text)
                  (insert appt-text)))))))
      (dolist (appt appts)
        (let* ((appt-date (first appt))
               (appt-desc (second appt))
               (appt-category (when (string-match "\\(.*\\)(\\(.*\\))$" 
appt-desc)
                                (match-string 2 appt-desc)))
               (appt-text (when (string-match "\\(.*\\)\\((.*)\\)?$" appt-desc)
                                (match-string 1 appt-desc))))
          ;; Filter task appointments only:
          (when (and appt-text
                     (string-match "[EMAIL PROTECTED](.*\\)[    ]*|?[   ]#[     
 ]*[-|]?\\(.*\\)$" appt-text)
                     ;; Now filter by categories regexp:
                     (or (null appt-category)
                         (save-match-data  (string-match category-regexp 
appt-category))))
            ;; Extract time and text strings:
                (let ((appt-time (match-string 1 appt-text))
                      (appt-text (match-string 2 appt-text)))
                  (setq appt-time (replace-in-string appt-time "|" ""))
                  (setq appt-time (replace-in-string appt-time " [ ]*" " "))
                  (setq appt-time (replace-in-string appt-time " $" ""))
                  (setq appt-time (replace-in-string appt-time " " "-"))
                  (setq appt-date (apply #'format "%s/%s/%s" 
(planner-filename-to-calendar-date appt-date)))
                  (message "Adding task to temp diary:::: %s %s %s" appt-date 
appt-time appt-text)
                  (insert (format "%s %s %s\n" appt-date appt-time 
appt-text))))))
        (icalendar-export-region (point-min)
                                 (point-max)
                                 ical-output-file))))

;; icalendar fix (this function wouldn't work properly under my Windows + GNU
;; Emacs configuration, so I just removed a silly comparison:
(defalias 'icalendar--rris 'replace-regexp-in-string)


(defun planner-publish-ical (arg &optional destination)
  "Publish a calendar to DESTINATION (defaults to a local file, 
\"~/exported-planner-appts.ics\")."
  (interactive "p")
  (let ((destination (or destination
                         (if (= arg 0)
                             "~/exported-planner-appts.ics"
                             (concat personal-wiki-remote-publish-location 
"/exported-planner-appts.ics")))))
    (with-current-buffer (current-buffer)
      (find-file destination)
      (goto-char (point-min))
      (delete-matching-lines ".")
      (save-buffer))
    (planner-export-ical "." 20 destination)))




Cheers!
    
-- 
Edgar Gonçalves
Software Engineering Group @ INESC-ID
IST/Technical University of Lisbon
Rua Alves Redol, 9, Room 635              
1000-029 Lisboa, Portugal                 
mailto:edgar[DOT]goncalves[AT]inesc[DASH]id[DOT]pt
http://www.esw.inesc-id.pt/~eemg


_______________________________________________
Planner-el-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/planner-el-discuss

Reply via email to