From: Eric S Fraga <ucecesf@ucl.ac.uk>
To: Daniel Martins <danielemc@gmail.com>
Cc: org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Google calendar to org mode script and a feature request for agenda
Date: Thu, 08 Jul 2010 19:07:33 +0100 [thread overview]
Message-ID: <87k4p57spm.wl%ucecesf@ucl.ac.uk> (raw)
In-Reply-To: <AANLkTikUD8Iw4prKlD-T84OQW_FGgC3VCL072A2oBBL0@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1435 bytes --]
On Wed, 7 Jul 2010 17:38:45 -0300, Daniel Martins <danielemc@gmail.com> wrote:
>
> Eric,
>
> Your awk seems to get timed appts in GMT
>
> How can I adapt it to GMT-3
>
> Daniel
Okay! I think I've got this working for any time zone (as well as
adding some more functionality -- read the prologue in the script for
info).
Attached is the awk script. I use this from within a shell script (on
Linux) that essentially does this:
--8<---------------cut here---------------start------------->8---
ICS=basic.ics
ORG=googlecalendar.org
AWK=ical2org.awk
# get the Google calendar
wget http://www.google.com/calendar/ical/[...]/basic.ics
# convert the ical entries to org format, adjusting for the
# time zone information
# this next command yields hours from UTC, + or -, times 100
# Note: this does not cater for those people living in time zones
# that are not aligned with discrete hours (e.g. Newfoundland)...
timezone=$(date +%z | sed 's/^\([+-]\)0/\1/')
# convert this to seconds for use in the awk script
seconds=$(($timezone*36))
# and now process the ics file with appropriate time zone
awk -f $AWK --assign SECONDS=$seconds < $ICS > $ORG
--8<---------------cut here---------------end--------------->8---
Please test this all out and let me know if it works. If the date and
sed commands work, you should be adjusting the times by -3*3600=-10800
seconds. This seems to be working for me with BST (aka GMT+1).
eric
[-- Attachment #2: ical2org.awk --]
[-- Type: text/plain, Size: 5496 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 --assign SECONDS=SSSS < icalinputfile.ics > orgmodeentries.org
#
# where "SSSS" is the number of seconds to adjust time to take into
# account the local time zone relative to UTC (e.g. GMT+1 == 3600,
# GMT-1 == -3600). 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...
#
# Note: change org meta information generated below for author and
# email entries!
#
# Known bugs:
# - if the iCal entry has an event reminder, the description field in
# the VALARM entry for the event will supercede the description field
# of the originating entry.
# - 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)
#----------------------------------------------------------------------------------
# a function to take the iCal formatted date+time, converted it into
# an internal form (seconds since time 0), and adjust according to the
# local time zone (specified by +-SECONDS on the argument to awk)
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
timestamp = mktime(datespec);
# print "time stamp : " timestamp;
# and adjust for the time zone, number of seconds from GMT/UTC.
timestamp += 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 = ":";
date = "";
time2given = 0;
entry = ""
icalentry = "" # the full entry for inspection
headline = ""
id = ""
indescription = 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: google"
print " "
}
# any line that starts at the left with a non-space character is a new data field
/^[A-Z]/ {
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;VALUE=DATE/ {
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 %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 = gensub("\r", "", "g", $0);
indescription = 1;
}
# 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
/^ / {
# print "** continuation line: " $0
if (indescription) {
entry = entry gensub("\r", "", "g", $0);
} else if (insummary) {
summary = summary gensub("\r", "", "g", $0)
}
icalentry = icalentry "\n" $0
}
# 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/ {
print "* " 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 ""
print gensub("\\\\n", "\n", "g", entry); # need 4 backslash to get one in the pattern!
print "** COMMENT original iCal entry"
print gensub("\r", "", "g", icalentry)
summary = ""
date = ""
entry = ""
icalentry = ""
indescription = 0
}
[-- Attachment #3: Type: text/plain, Size: 75 bytes --]
--
Eric S Fraga
GnuPG: 8F5C 279D 3907 E14A 5C29 570D C891 93D8 FFFC F67D
[-- 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
next prev parent reply other threads:[~2010-07-08 20:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-29 22:28 Google calendar to org mode script and a feature request for agenda Eric S Fraga
2010-06-30 5:43 ` Stephen Eglen
2010-06-30 8:14 ` Eric S Fraga
2010-07-07 20:38 ` Daniel Martins
2010-07-07 22:17 ` Eric S Fraga
2010-07-07 22:57 ` Daniel Martins
2010-07-08 18:07 ` Eric S Fraga [this message]
-- strict thread matches above, loose matches on Subject: below --
2010-07-09 0:57 Torsten Wagner
2010-07-09 1:54 ` Nick Dokos
2010-07-09 8:30 ` Eric S Fraga
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k4p57spm.wl%ucecesf@ucl.ac.uk \
--to=ucecesf@ucl.ac.uk \
--cc=danielemc@gmail.com \
--cc=e.fraga@ucl.ac.uk \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.