Created
January 7, 2014 17:43
-
-
Save hinnerk/8303265 to your computer and use it in GitHub Desktop.
Why would anyone ever write an awk script? This one converts some parts of an ics calender file to the remind format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
# ics2rem by Hinnerk Haardt <hinnerk@randnotizen.de> | |
# | |
# Converts output of iCalendar to remind | |
# usage: cat FILENAME.ics | rem2ics > reminders.rem | |
# | |
# THE FOLLOWING CODE IS RELEASED INTO THE PUBLIC DOMAIN | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE | |
BEGIN { | |
RS = "\n" | |
FS = ":" | |
ORS = " " | |
# names of months | |
month["01"] = "Jan" | |
month["02"] = "Feb" | |
month["03"] = "Mar" | |
month["04"] = "Apr" | |
month["05"] = "May" | |
month["06"] = "Jun" | |
month["07"] = "Jul" | |
month["08"] = "Aug" | |
month["09"] = "Sep" | |
month["10"] = "Okt" | |
month["11"] = "Nov" | |
month["12"] = "Dec" | |
# timezones (not used, for further reference) | |
timezone["Europe/Berlin"] = "-2" | |
} | |
{ | |
if ($1 == "END" && $2 == "VEVENT") { | |
# DESCRIPTION | |
if (event["vevent","DESCRIPTION"]!="") | |
event["vevent","DESCRIPTION"] = (" (" event["vevent","DESCRIPTION"] ")") | |
# STARTDATE | |
for (option in event) { | |
if (option ~ /^vevent.*DTSTART.*/) | |
startdate["full"] = event[option] | |
# DTSTART sometimes contains additional information... | |
if (option ~ /^vevent.*DTSTART;.*/) { | |
split(option, dtstarttrasharray, ";" ) | |
# ... that sometimes is the timezone | |
if (dtstarttrasharray["2"] ~ /^TZID.*/) { | |
split(dtstarttrasharray["2"], localtimezonearray, "=") | |
startdate["timezone"] = localtimezonearray["2"] | |
} | |
# clean up | |
split("", localtimezonearray) | |
split("", dtstarttrasharray) | |
} | |
startdate["year"] = substr(startdate["full"],0,4) | |
startdate["month"] = substr(startdate["full"],5,2) | |
startdate["day"] = substr(startdate["full"],7,2) | |
if (startdate["full"] ~ /.*T.*/) { | |
startdate["hour"] = substr(startdate["full"],10,2) | |
startdate["minute"] = substr(startdate["full"],12,2) | |
startdate["second"] = substr(startdate["full"],14,2) | |
if (startdate["hour"] != "00") | |
# no seconds exported... (startdate["second"]) | |
startdate["time"] = ("AT " startdate["hour"]":" startdate["minute"]) | |
} | |
startdate["remind"] = (month[startdate["month"]] " " startdate["day"] " " startdate["year"] " " startdate["time"]) | |
} | |
# DURATION | |
if (option == "DURATION") { | |
duration = event[option] | |
# ... and adjusted. | |
# !FIXME: Format: "P[numD]T[numH][numM]", "num" is a integer | |
#sub([0-9*d], womit, duration) | |
duration = (" " duration) | |
} | |
# !TODO: ATTENDEE, X-WR-ALARMID:SOUNDALARM, ACTION, | |
# ATTACH, X-WR-ALARMID:DISPLAYALARM, TRIGGER | |
# STATUS, SEQUENCE(?, Timezone Array calc(?), | |
# | |
# !FIXME calculate: startdate + DURATION => enddate | |
# print the remind line | |
print "REM " startdate["remind"] " MSG " event["vevent","SUMMARY"] event["vevent","DESCRIPTION"] "\n" | |
# clean up vars and arrays: | |
split("", event) | |
split("", startdate) | |
} | |
else | |
# !FIXME: Ungetestet, soll EVENT und ALARM voneinander unterscheidbar machen: | |
# !FIXME: Muß noch oben geändert werden, wenn es funktioniert. | |
if ($1 == "BEGIN" && $2 == "VALARM") | |
arrayname = "valarm" | |
if ($1 == "BEGIN" && $2 == "VEVENT") | |
arrayname = "vevent" | |
event[arrayname,$1] = $2 | |
} | |
# END {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment