From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric S Fraga Subject: Diary synchronising with Google calendar (was Re: Google CL and org-mode) Date: Tue, 06 Jul 2010 16:30:25 +0100 Message-ID: <87y6dopqzy.wl%ucecesf@ucl.ac.uk> References: <19503.26717.462263.759346@gargle.gargle.HOWL> <29444366.20665.1278322512578.JavaMail.root@zm-cesbio-01> <19505.56156.671868.967808@gargle.gargle.HOWL> <87tyodfvbr.wl%ucecesf@ucl.ac.uk> Reply-To: e.fraga@ucl.ac.uk Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Tue_Jul__6_16:30:25_2010-1" Return-path: Received: from [140.186.70.92] (port=44840 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWCmU-0004G2-Cm for emacs-orgmode@gnu.org; Tue, 06 Jul 2010 14:22:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OWCmS-0004BM-Ub for emacs-orgmode@gnu.org; Tue, 06 Jul 2010 14:22:06 -0400 Received: from vscane-a.ucl.ac.uk ([144.82.108.41]:45494) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OWCmS-00049u-N9 for emacs-orgmode@gnu.org; Tue, 06 Jul 2010 14:22:04 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Daniel Mahler Cc: org-mode mailing list --Multipart_Tue_Jul__6_16:30:25_2010-1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, 6 Jul 2010 00:14:00 +0200, Daniel Mahler wrote: >=20 > On Mon, Jul 5, 2010 at 11:54 PM, Eric S Fraga wrote: > > On Mon, 5 Jul 2010 17:10:55 +0200, Daniel Mahler wr= ote: > >> > >> Hi, > >> > >> Have you looked at g-client? > > > > Thanks. =C2=A0I did look at g-client a long time ago. =C2=A0It should p= rovide > > everything we need but it's much more than I want to even start > > considering... =C2=A0I just don't have the time unfortunately. > > > > The google command line scripts, on the other hand, are > > straightforward and will give me (others?) 90% of the functionality I > > want. > > > > Mind you, I've been playing a bit and Google's "quick add" syntax > > leaves a bit to be desired. =C2=A0There's no formal specification and it > > doesn't quite work, especially trying to get a repeated entry at a > > given time of day. > > >=20 > GoogleCL is actually a rather thin wrapper around the gdata python > client library, > which essentially just adds the commandline processing. > Maybe the way to go is to call gdata directly via pymacs. >=20 > cheers > Daniel Yes, using pymacs and interacting directly with Google's API may be the way to go. However, given my usual time constraints, I'm going for the 80% solution, as described below: My use case is that I spend almost all of time in Emacs (and almost all of that time within org) but I am sometimes but not often away from one of my computers with only my Android phone. When I'm away from the computers, I need to be able to check my diary and maybe make the odd addition to it. I am not particularly concerned with note taking with my mobile phone (too annoying! and MobileOrg is probably a better solution for synchronised note taking in any case...) so the following meets this use case. I have two relevant org files: diary.org and googlecalendar.org. The first is the default target for inserting diary entries from org's agenda view; the latter contains all items scheduled from within Google's calendar application, typically from my phone, and downloaded and processed using the awk script I posted to this list last week. On the Google calendar side, I have two calendars: the default and one called "org". The first is used when I actually schedule something using Google. The latter is populated directly by org using Google's command line scripts with this advice on org's diary insertion function: #+begin_src emacs-lisp (defadvice org-agenda-add-entry-to-org-agenda-diary-file=20 (after add-to-google-calendar) "Add a new Google calendar entry that mirrors the diary entry just create= d by org-mode." (let ((type (ad-get-arg 0)) (text (ad-get-arg 1)) (d1 (ad-get-arg 2)) (year1 (nth 2 d1)) (month1 (car d1)) (day1 (nth 1 d1)) (d2 (ad-get-arg 3)) entry dates) (if (or (not (eq type 'block)) (not d2)) (setq dates (format "%d-%02d-%02d" year1 month1 day1)) (let ((year2 (nth 2 d2)) (month2 (car d2)) (day2 (nth 1 d2)) (repeats= (- (calendar-absolute-from-gregorian d1) (calendar-absolute-from-gregorian d2)))) (if (> repeats 0) (setq dates (format "%d-%02d-%02d every day for %d days" year1 month1 = day1 (abs repeats))) (setq dates (format "%d-%02d-%02d every day for %d days" year1 month1 da= y1 (abs repeats)))) )) (setq entry (format "/usr/bin/google calendar add --cal org \"%s on %s= \"" text dates)) ;;(message entry) (if (not (string=3D "MYLAPTOPCOMPUTER" mail-host-address)) (shell-command entry) (let ((offline "~/tmp/org2google-offline-entries")) (find-file offline) (goto-char (point-max)) (insert (concat entry "\n")) (save-buffer) (kill-buffer (current-buffer)) (message "Plain text written to %s" offline))))) (ad-activate 'org-agenda-add-entry-to-org-agenda-diary-file) #end_src This does two things depending on my online status which is implicitly defined by the host address of the computer I am using (yes, kludgy at best): if online, the headline entry for the new diary entry (which is stored in diary.org) is sent to my "org" Google calendar. If offline, the command line that would have been used is stored in a file. When I got back online, I simply execute and empty this file as part of a more general synchronisation step (including git updates for my org files and sending any composed emails like this one ;-). This 2x2 approach (two diaries in org, two calendars in Google) seems to be working very well. It works for me because I seldom delete items in my diary and, in any case, I'd rather err on having an entry that no longer makes sense than end up double-booked. Repeated events with times, however, do not work as Google's "Quick Add" feature, on which the command line script depends, doesn't quite work. So only timed events for a single day or repeated daily non-timed events are processed correctly. There is also little (well, nothing) in the way of error checking in this advice... I hope this is of some use to people! I'm really enjoying my Android phone together with org! eric --Multipart_Tue_Jul__6_16:30:25_2010-1 Content-Type: text/plain; charset=US-ASCII -- Eric S Fraga GnuPG: 8F5C 279D 3907 E14A 5C29 570D C891 93D8 FFFC F67D --Multipart_Tue_Jul__6_16:30:25_2010-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Multipart_Tue_Jul__6_16:30:25_2010-1--