~robertgzr/remind

08e9c586fc049632888705a11d5d6db8b84d07fc — Robert Günzler 1 year, 4 months ago 03a2090 master
add scripts for converting between ics and rem files
4 files changed, 152 insertions(+), 0 deletions(-)

A cmd/ics2rem/main.go
A cmd/rem2ics/main.go
A examples/test.ics
A examples/test.rem
A cmd/ics2rem/main.go => cmd/ics2rem/main.go +38 -0
@@ 0,0 1,38 @@
package main

import (
	"flag"
	"fmt"
	"log"
	"os"

	"github.com/emersion/go-ical"

	"git.sr.ht/~robertgzr/remind"
)

func main() {
	flag.Parse()
	log.SetOutput(os.Stderr)

	fd, err := os.Open(flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}
	defer fd.Close()

	cal, err := ical.NewDecoder(fd).Decode()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprintf(os.Stdout, ";; this file is auto-generated.\n")
	for _, comp := range cal.Children {
		rem, err := remind.ReminderFromComponent(comp)
		if err != nil {
			log.Print(err)
			continue
		}
		fmt.Fprintf(os.Stdout, "%s\n", rem)
	}
}

A cmd/rem2ics/main.go => cmd/rem2ics/main.go +45 -0
@@ 0,0 1,45 @@
package main

import (
	"bufio"
	"flag"
	"log"
	"os"

	"git.sr.ht/~robertgzr/remind"
	"github.com/emersion/go-ical"
)

func main() {
	flag.Parse()
	log.SetOutput(os.Stderr)

	fd, err := os.Open(flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}
	defer fd.Close()

	cal := ical.NewCalendar()
	cal.Props.SetText(ical.PropVersion, "2.0")
	cal.Props.SetText(ical.PropProductID, "-//~robertgzr/remind//NONSGML PDA Calendar Version 1.0//EN")

	lines := bufio.NewScanner(fd)
	for lines.Scan() {
		line := lines.Text()
		// skip empty lines and comments
		if len(line) < 1 || line[0] == ';' {
			continue
		}
		rem, err := remind.ParseReminder(line)
		if err != nil {
			log.Print(err)
			continue
		}
		cal.Children = append(cal.Children, rem.Component())
	}

	if err := ical.NewEncoder(os.Stdout).Encode(cal); err != nil {
		log.Fatal(err)
	}
}

A examples/test.ics => examples/test.ics +63 -0
@@ 0,0 1,63 @@
BEGIN:VCALENDAR
X-WR-CALNAME:Personal Calendar
PRODID:-//Inverse inc./SOGo 5.5.0//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:Europe/Berlin
LAST-MODIFIED:20220816T024022Z
BEGIN:DAYLIGHT
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
DTSTART:19810329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
DTSTART:19961027T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20220902T181606Z
UID:4fae4a07-8c3c-44e8-8280-560daa2a5239
SUMMARY:MAMA EUROPA - Deutschland Premiere
LOCATION:Schaubude Berlin
DESCRIPTION:MAMA EUROPA - Deutschland Premiere\, 9. September 2022\, 20:00 
 Uhr
DTSTART;TZID=Europe/Berlin:20220909T200000
DTEND;TZID=Europe/Berlin:20220909T210000
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20220903T124026Z
UID:73274e55-c406-4f17-a9b7-9cc9912ef9f5
SEQUENCE:1
SUMMARY:El Grito Mexikanisches Volksfest
LOCATION:Osthafen (Berlin)
DESCRIPTION:www.vivamexiko.com
DTSTART;TZID=Europe/Berlin:20220917T120000
DTEND;TZID=Europe/Berlin:20220918T220000
STATUS:CONFIRMED
CLASS:PUBLIC
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20220902T181413Z
UID:f24d9d79-4e3c-4cb9-a3e8-26f04e3f34b1
SUMMARY:kinofest
DESCRIPTION:https://www.yorck.de/kinofest
DTSTART;VALUE=DATE:20220910
DTEND;VALUE=DATE:20220912
TRANSP:TRANSPARENT
CLASS:PUBLIC
END:VEVENT
BEGIN:VTODO
DTSTAMP;TZID=Local:20221007T142044
DUE;TZID=Local:20221008T120000
SUMMARY:foo bar
UID:eaab2646e8be789bd43c468a25917b5c
END:VTODO
END:VCALENDAR

A examples/test.rem => examples/test.rem +6 -0
@@ 0,0 1,6 @@
;; this should create VEVENT
REM 3 Oct MSG Tag der Deutschen Einheit
REM 24 Dec MSG Heiligabend

;; this should create VTODO
REM 8 Oct 2022 AT 12:00 MSG TODO: foo bar