dot

packages and services management
Log | Files | Refs | README

commit 2b30de6ab29d0d25f5148161bde8aa27ca78eca3
parent 3f806fd9f7540fc8f1d5e99a8335b1b6b6d2c683
Author: josuah <mail@josuah.net>
Date:   Thu, 22 Dec 2016 23:44:02 +0000

Generating clean output

Diffstat:
M.local/bin/ical | 42+++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/.local/bin/ical b/.local/bin/ical @@ -1,8 +1,12 @@ +#!/usr/bin/awk -f + + function is_bissextile(year) { return (year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0); } + function days_in_month(month, year) { if (month == 2) { @@ -26,6 +30,17 @@ function date_to_second(year, month, day, hour, minute, second) return (second + 60 * (minute + 60 * (hour + (24 * (day - 1))))); } +function format_date(date) +{ + return strftime("%Y-%m-%d-%H-%M-%S", date_to_second( \ + substr(date, 1, 4), # Year + substr(date, 5, 2), # Month + substr(date, 7, 2), # Day + substr(date, 10, 2), # Hour + substr(date, 12, 2), # Minute + substr(date, 14, 2))); # Second +} + BEGIN { FS = ":"; @@ -34,6 +49,7 @@ BEGIN { { gsub("\015", ""); + gsub("\t", " "); } @@ -49,26 +65,14 @@ BEGIN { /END:VEVENT/ { + name = format_date(vevent["DTSTART"]) "_" format_date(vevent["DTEND"])); - date = vevent["DTSTART"] - printf "%s ", strftime("%Y%m%dT%H%M%SZ", date_to_second( \ - substr(date, 1, 4), # Year - substr(date, 5, 2), # Month - substr(date, 7, 2), # Day - substr(date, 10, 2), # Hour - substr(date, 12, 2), # Minute - substr(date, 14, 2))); # Second + gsub(/\\/, "", vevent["LOCATION"]); + printf("SUM: %s\n", vevent["SUMMARY"]); - date = vevent["DTEND"] - printf "%s ", strftime("%Y%m%dT%H%M%SZ", date_to_second( \ - substr(date, 1, 4), # Year - substr(date, 5, 2), # Month - substr(date, 7, 2), # Day - substr(date, 10, 2), # Hour - substr(date, 12, 2), # Minute - substr(date, 14, 2))); # Second + gsub(/\\/, "", vevent["LOCATION"]); + printf("LOC: %s\n", vevent["LOCATION"]); - printf("%s\t", vevent["SUMMARY"]); - printf("%s\t", vevent["LOCATION"]); - printf("%s\n", vevent["DESCRIPTION"]); + gsub(/\\n/, "\n", vevent["DESCRIPTION"]); + printf("\n%s\n", vevent["DESCRIPTION"]); }