emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric S Fraga <e.fraga@ucl.ac.uk>
To: Arun Persaud <apersaud@lbl.gov>
Cc: emacs-orgmode@gnu.org
Subject: Re: Status google calendar sync
Date: Fri, 28 Jan 2011 16:13:11 +0000	[thread overview]
Message-ID: <8739odqa5k.fsf@ucl.ac.uk> (raw)
In-Reply-To: <4D41EA60.50002@lbl.gov> (Arun Persaud's message of "Thu, 27 Jan 2011 13:57:52 -0800")

[-- Attachment #1: Type: text/plain, Size: 1212 bytes --]

Arun Persaud <apersaud@lbl.gov> writes:

[...]

> I also tried the ics2org script, but run into some problems
> there... the

do you mean my ical2org.awk script?  or something else?

> script didn't recognize the timestamps, which for me look like:
>
> DTSTART;TZID=America/Los_Angeles:20110127T110000
>
> and I think the timezone messes things up. I wanted to ask if the script
> exists on github or somewhere similar, if not it would be great, if we
> could upload it, so that it is easy to work on it for several
> people...

if you are indeed referring to my awk script, you are correct: I don't
catch these lines.  Can you try the attached version?  It works for me
but I don't actually have any ical/ics files that have entries like that
one above.

>
> Eric:I could upload it if this is ok for you? (what's the license on the
> file?)

Please feel free to upload it to Worg.  I do actually have a task for
myself to upload this and related scripts and to write some
documentation (essentially what I wrote in my long email months ago when
I posted these scripts) but I have just not had the time to spare (bad
time of year work-wise...).  It's free to use, modify, copy, etc. No
warranty blah blah blah.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: awk script to convert ical entries to org --]
[-- Type: text/x-awk, Size: 7062 bytes --]

# awk script for converting an iCal formatted file to a sequence of org-mode headings.
# this may not work in general but seems to work for day and timed events from Google's
# calendar, which is really all I need right now...
#
# usage:
#   awk -f THISFILE < icalinputfile.ics > orgmodeentries.org
#
# Note: change org meta information generated below for author and
# email entries!
#
# Known bugs:
# - not so much a bug as a possible assumption: date entries with no time
#   specified are assumed to be independent of the time zone.
#
# Eric S Fraga
# 20100629 - initial version
# 20100708 - added end times to timed events
#          - adjust times according to time zone information
#          - fixed incorrect transfer for entries with ":" embedded within the text
#          - added support for multi-line summary entries (which become headlines)
# 20100709 - incorporated time zone identification
#          - fixed processing of continuation lines as Google seems to
#            have changed, in the last day, the number of spaces at
#            the start of the line for each continuation...
#          - remove backslashes used to protect commas in iCal text entries
# no further revision log after this as the file was moved into a git
# repository...
#
# Last change: 2011.01.28 16:08:03
#----------------------------------------------------------------------------------

# a function to take the iCal formatted date+time, convert it into an
# internal form (seconds since time 0), and adjust according to the
# local time zone (specified by +-seconds calculated in the BEGIN
# section)

function datetimestamp(input)
{
    # convert the iCal Date+Time entry to a format that mktime can understand
    datespec = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])T([0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]*", "\\1 \\2 \\3 \\4 \\5 \\6", "g", input);
    # print "date spec : " datespec; convert this date+time into
    # seconds from the beginning of time and include adjustment for
    # time zone, as determined in the BEGIN section below.  For time
    # zone adjustment, I have not tested edge effects, specifically
    # what happens when UTC time is a different day to local time and
    # especially when an event with a duration crosses midnight in UTC
    # time.  It should work but...
    timestamp = mktime(datespec) + seconds;
    # print "adjusted    : " timestamp
    # print "Time stamp  : " strftime("%Y-%m-%d %H:%M", timestamp);
    return timestamp;
}

BEGIN {
    # use a colon to separate the type of data line from the actual contents
    FS = ":";
    
    # determine the number of seconds to use for adjusting for time
    # zone difference from UTC.  This is used in the function
    # datetimestamp above.  The time zone information returned by
    # strftime() is in hours * 100 so we multiply by 36 to get
    # seconds.  This does not work for time zones that are not an
    # integral multiple of hours (e.g. Newfoundland)
    seconds = gensub("([+-])0", "\\1", "", strftime("%z")) * 36;
    
    date = "";
    entry = ""
    first = 1;			# true until an event has been found
    headline = ""
    icalentry = ""  # the full entry for inspection
    id = ""
    indescription = 0;
    time2given = 0;
    
    print "#+TITLE:     Main Google calendar entries"
    print "#+AUTHOR:    Eric S Fraga"
    print "#+EMAIL:     e.fraga@ucl.ac.uk"
    print "#+DESCRIPTION: converted using the ical2org awk script"
    print "#+CATEGORY: " NAME
    print " "
}

# continuation lines (at least from Google) start with two spaces
# if the continuation is after a description or a summary, append the entry
# to the respective variable

/^[ ]+/ { 
    if (indescription) {
	entry = entry gensub("\r", "", "g", gensub("^[ ]+", "", "", $0));
    } else if (insummary) {
	summary = summary gensub("\r", "", "g", gensub("^[ ]+", "", "", $0))
    }
    icalentry = icalentry "\n" $0
}

/^BEGIN:VEVENT/ {
    # start of an event.  if this is the first, output the preamble from the iCal file
    if (first) {
	print "* COMMENT original iCal preamble"
	print gensub("\r", "", "g", icalentry)
	icalentry = ""
    }
    first = false;
}
# any line that starts at the left with a non-space character is a new data field

/^[A-Z]/ {
    # we ignore DTSTAMP lines as they change every time you download
    # the iCal format file which leads to a change in the converted
    # org file as I output the original input.  This change, which is
    # really content free, makes a revision control system update the
    # repository and confuses.
    if (! index("DTSTAMP", $1)) icalentry = icalentry "\n" $0
    # this line terminates the collection of description and summary entries
    indescription = 0;
    insummary = 0;
}

# this type of entry represents a day entry, not timed, with date stamp YYYYMMDD

/^DTSTART;[^:]*/ {
    date = gensub("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*[\r]", "\\1-\\2-\\3", "g", $2)
    # print date
}

# this represents a timed entry with date and time stamp YYYYMMDDTHHMMSS
# we ignore the seconds

/^DTSTART:/ {
    # print $0
    date = strftime("%Y-%m-%d %a %H:%M", datetimestamp($2));
    # print date;
}

# and the same for the end date; here we extract only the time and append this to the 
# date+time found by the DTSTART entry.  We assume that entry was there, of course.
# should probably add some error checking here!  In time...

/^DTEND:/ {
    # print $0
    time2 = strftime("%H:%M", datetimestamp($2));
    date = date "-" time2;
}

# The description will the contents of the entry in org-mode.
# this line may be continued.

/^DESCRIPTION/ { 
    $1 = "";
    entry = entry "\n" gensub("\r", "", "g", $0);
    indescription = 1;
}

# the summary will be the org heading

/^SUMMARY/ { 
    $1 = "";
    summary = gensub("\r", "", "g", $0);
    insummary = 1;
}

# the unique ID will be stored as a property of the entry

/^UID/ { 
    $1 = "";
    id = gensub("\r", "", "g", $0);
}

# when we reach the end of the event line, we output everything we
# have collected so far, creating a top level org headline with the
# date/time stamp, unique ID property and the contents, if any

/^END:VEVENT/ {
    # translate \n sequences to actual newlines and unprotect commas (,)
    print "* " gensub("\\\\,", ",", "g", gensub("\\\\n", " ", "g", summary))
    print "  :PROPERTIES:"
    print "  :ID:       " id
    print "  :END:"
    print "  <" date ">"
    # for the entry, convert all embedded "\n" strings to actual newlines
    print ""
    # translate \n sequences to actual newlines and unprotect commas (,)
    print gensub("\\\\,", ",", "g", gensub("\\\\n", "\n", "g", entry));
    print "** COMMENT original iCal entry"
    print gensub("\r", "", "g", icalentry)
    summary = ""
    date = ""
    entry = ""
    icalentry = ""
    indescription = 0
    insummary = 0
}

# Local Variables:
# time-stamp-line-limit: 1000
# time-stamp-format: "%04y.%02m.%02d %02H:%02M:%02S"
# time-stamp-active: t
# time-stamp-start: "Last change:[ \t]+"
# time-stamp-end: "$"
# End:

[-- Attachment #3: Type: text/plain, Size: 127 bytes --]



-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.4 (release_7.4.257.g5d90.dirty)

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
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

  reply	other threads:[~2011-01-28 16:13 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21  8:38 Status google calendar sync Torsten Wagner
2011-01-21  9:43 ` Ian Barton
2011-01-21 15:22   ` Nick Dokos
2011-01-21 18:19   ` Arun Persaud
2011-01-21 23:58     ` Eric S Fraga
2011-01-25 20:21       ` Arun Persaud
2011-01-26 12:33         ` Eric S Fraga
2011-01-26 23:29           ` Mark Elston
2011-01-27  0:52             ` Arun Persaud
2011-01-27  2:51               ` Mark Elston
2011-01-27 19:43                 ` Arun Persaud
2011-01-27 21:57                 ` Arun Persaud
2011-01-28 16:13                   ` Eric S Fraga [this message]
2011-01-31 19:03                     ` Bastien
2011-01-29  1:28 ` Greg Troxel
2011-01-29 12:45   ` Eric S Fraga
  -- strict thread matches above, loose matches on Subject: below --
2011-01-29 14:53 Torsten Wagner
2011-01-29 19:38 ` Mark Elston
2011-01-29 20:44   ` Greg Troxel
2011-01-30  4:36     ` Mark Elston
2011-01-30 13:28       ` Greg Troxel
2011-01-30 14:09         ` Eric S Fraga
2011-01-30 20:43           ` Arun Persaud
2011-01-30 21:36         ` Mark Elston
2011-01-30 14:01       ` Eric S Fraga
2011-01-30  1:21 ` Eric S Fraga
2011-01-31 10:02   ` Christopher Witte
2011-02-01  9:07     ` Eric S Fraga
2011-02-01  0:54 Torsten Wagner
2011-02-01  9:12 ` Eric S Fraga
2011-02-01 22:44 ` Sven Bretfeld
2011-02-02  5:15   ` Torsten Wagner
2011-02-02  8:30     ` Konrad Hinsen
2011-02-14 21:39       ` Marcelo de Moraes Serpa
2011-02-15  7:18         ` Konrad Hinsen
2011-02-15 16:37           ` Marcelo de Moraes Serpa
2011-02-15 16:43             ` Marcelo de Moraes Serpa
2011-02-15 16:55               ` Bastien
2011-06-10 16:58           ` Stephen Eglen
2011-06-10 17:04             ` Arun Persaud
2011-06-10 18:34               ` Stephen Eglen
2011-06-10 19:09                 ` Arun Persaud
2011-06-11 13:25                   ` Philipp Haselwarter
2011-06-11 18:38                     ` Nick Dokos
2011-06-15 19:00                       ` Eric S Fraga
2011-06-11 17:32                 ` Niels Giesen
2011-06-30 16:14                   ` Bastien
2011-06-15 18:45                 ` Eric S Fraga
     [not found]                 ` <87hb7rory9.fsf@ucl.ac.uk>
2011-06-16 12:13                   ` Stephen Eglen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8739odqa5k.fsf@ucl.ac.uk \
    --to=e.fraga@ucl.ac.uk \
    --cc=apersaud@lbl.gov \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).