~psic4t/qcal

c1f0f864e5138215b118183943348c09083a25e8 — psic4t 9 months ago 93e8dfe 0.8.3
cleanup
4 files changed, 26 insertions(+), 31 deletions(-)

M defines.go
M helpers.go
M main.go
M parse.go
M defines.go => defines.go +13 -1
@@ 63,7 63,19 @@ type configStruct struct {
	DefaultNumDays int
}

type props struct {
type Event struct {
	Href        string
	Color       string
	Start       time.Time
	End         time.Time
	TZID        string
	Freq        string
	Summary     string
	Description string
	Location    string
}

type xmlProps struct {
	calNo        string
	Url          string
	XMLName      xml.Name `xml:"multistatus"`

M helpers.go => helpers.go +2 -5
@@ 11,7 11,6 @@ import (
	"net/http"
	"os"
	"path"
	"regexp"
	"sort"
	"strconv"
	"strings"


@@ 79,7 78,7 @@ func getCalProp(calNo int, p *[]calProps, wg *sync.WaitGroup) {
	if config.Calendars[calNo].Username == "" {
		displayName = parseIcalName(string(xmlContent))
	} else {
		xmlProps := props{}
		xmlProps := xmlProps{}
		err = xml.Unmarshal(xmlContent, &xmlProps)
		if err != nil {
			log.Fatal(err)


@@ 291,10 290,8 @@ func displayICS() {
	}

	eventData, _ := explodeEvent(&icsData)
	reFr, _ := regexp.Compile(`FREQ=[^;]*(;){0,1}`)
	freq := trimField(reFr.FindString(parseEventRRule(&eventData)), `(FREQ=|;)`)

	parseMain(&eventData, &elements, freq, "none", "none")
	parseMain(&eventData, &elements, "none", "none")
	for _, e := range elements {
		e.icsOutput()
	}

M main.go => main.go +3 -12
@@ 10,7 10,6 @@ import (
	"net/http"
	"os"
	"os/exec"
	"regexp"
	"sort"
	"strconv"
	"strings"


@@ 67,9 66,7 @@ func fetchCalData(Url, Username, Password, Color string, cald *Caldata, wg *sync

			eventHref := ""
			eventColor := Color
			reFr, _ := regexp.Compile(`FREQ=[^;]*(;){0,1}`)
			freq := trimField(reFr.FindString(parseEventRRule(&eventData[i])), `(FREQ=|;)`)
			parseMain(&eventData[i], &elements, freq, eventHref, eventColor)
			parseMain(&eventData[i], &elements, eventHref, eventColor)
		}
	} else {



@@ 82,10 79,7 @@ func fetchCalData(Url, Username, Password, Color string, cald *Caldata, wg *sync

			eventData, _ = explodeEvent(&eventData) // vevent only

			reFr, _ := regexp.Compile(`FREQ=[^;]*(;){0,1}`)
			freq := trimField(reFr.FindString(parseEventRRule(&eventData)), `(FREQ=|;)`)

			parseMain(&eventData, &elements, freq, eventHref, eventColor)
			parseMain(&eventData, &elements, eventHref, eventColor)
		}
	}



@@ 119,10 113,7 @@ func showAppointments(singleCal string) {

		eventData, _ = explodeEvent(&eventData) // vevent only

		reFr, _ := regexp.Compile(`FREQ=[^;]*(;){0,1}`)
		freq := trimField(reFr.FindString(parseEventRRule(&eventData)), `(FREQ=|;)`)

		parseMain(&eventData, &elements, freq, eventHref, eventColor)
		parseMain(&eventData, &elements, eventHref, eventColor)
	}

	// time.Time sort by start time for events

M parse.go => parse.go +8 -13
@@ 26,18 26,6 @@ const (
	YmdHis = "2006-01-02 15:04:05"
)

type Event struct {
	Href        string
	Color       string
	Start       time.Time
	End         time.Time
	TZID        string
	Freq        string
	Summary     string
	Description string
	Location    string
}

func trimField(field, cutset string) string {
	re, _ := regexp.Compile(cutset)
	cutsetRem := re.ReplaceAllString(field, "")


@@ 186,6 174,12 @@ func parseEventRRule(eventData *string) string {
	return trimField(result, "RRULE:")
}

func parseEventFreq(eventData *string) string {
	re, _ := regexp.Compile(`FREQ=[^;]*(;){0,1}`)
	result := re.FindString(parseEventRRule(eventData))
	return trimField(result, `(FREQ=|;)`)
}

func parseICalTimezone(eventData *string) time.Location {
	re, _ := regexp.Compile(`X-WR-TIMEZONE:.*?\n`)
	result := re.FindString(*eventData)


@@ 202,10 196,11 @@ func parseICalTimezone(eventData *string) time.Location {
	return *loc
}

func parseMain(eventData *string, elementsP *[]Event, freq, href, color string) {
func parseMain(eventData *string, elementsP *[]Event, href, color string) {
	eventStart, tzId := parseEventStart(eventData)
	eventEnd, tzId := parseEventEnd(eventData)
	eventDuration := parseEventDuration(eventData)
	freq := parseEventFreq(eventData)

	if eventEnd.Before(eventStart) {
		eventEnd = eventStart.Add(eventDuration)