parse events
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
module astraltech.xyz/m/v2
|
||||||
|
|
||||||
|
go 1.26.1
|
||||||
|
|
||||||
|
require github.com/arran4/golang-ical v0.3.5 // indirect
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/arran4/golang-ical v0.3.5 h1:bbz6ld4dC+MmCKiFfOd6SkmIGnhNMBACZ485ULh7p9A=
|
||||||
|
github.com/arran4/golang-ical v0.3.5/go.mod h1:OnguFgjN0Hmx8jzpmWcC+AkHio94ujmLHKoaef7xQh8=
|
||||||
@@ -17,12 +17,10 @@ type PropStat struct {
|
|||||||
type Prop struct {
|
type Prop struct {
|
||||||
DisplayName string `xml:"displayname"`
|
DisplayName string `xml:"displayname"`
|
||||||
Type ResourceType `xml:"resourcetype"`
|
Type ResourceType `xml:"resourcetype"`
|
||||||
|
CalendarData string `xml:"calendar-data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceType struct {
|
type ResourceType struct {
|
||||||
Collection *struct{} `xml:"DAV: collection"`
|
Collection *struct{} `xml:"DAV: collection"`
|
||||||
Calendar *struct{} `xml:"urn:ietf:params:xml:ns:caldav calendar"`
|
Calendar *struct{} `xml:"urn:ietf:params:xml:ns:caldav calendar"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CalandarData struct {
|
|
||||||
}
|
|
||||||
|
|||||||
+9
-10
@@ -27,7 +27,7 @@ func init_dav_client() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Link string
|
CalData string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Calandar struct {
|
type Calandar struct {
|
||||||
@@ -95,19 +95,18 @@ const XML_cal string = `
|
|||||||
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||||
<D:prop>
|
<D:prop>
|
||||||
<D:getetag/>
|
<D:getetag/>
|
||||||
|
<C:calendar-data/>
|
||||||
</D:prop>
|
</D:prop>
|
||||||
|
|
||||||
|
<C:filter>
|
||||||
|
<C:comp-filter name="VCALENDAR">
|
||||||
|
<C:comp-filter name="VEVENT"/>
|
||||||
|
</C:comp-filter>
|
||||||
|
</C:filter>
|
||||||
|
|
||||||
</C:calendar-query>
|
</C:calendar-query>
|
||||||
`
|
`
|
||||||
|
|
||||||
// <C:calendar-data/>
|
|
||||||
|
|
||||||
// <C:filter>
|
|
||||||
// <C:comp-filter name="VCALENDAR">
|
|
||||||
// <C:comp-filter name="VEVENT"/>
|
|
||||||
// </C:comp-filter>
|
|
||||||
// </C:filter>
|
|
||||||
|
|
||||||
func get_calandar_data(cal Calandar, username string, password string) Calandar {
|
func get_calandar_data(cal Calandar, username string, password string) Calandar {
|
||||||
req, _ := http.NewRequest(
|
req, _ := http.NewRequest(
|
||||||
"REPORT",
|
"REPORT",
|
||||||
@@ -138,7 +137,7 @@ func get_calandar_data(cal Calandar, username string, password string) Calandar
|
|||||||
|
|
||||||
for i := range len(davResp.Responses) {
|
for i := range len(davResp.Responses) {
|
||||||
newEvent := Event{
|
newEvent := Event{
|
||||||
Link: serverConfig.URL + davResp.Responses[i].Href,
|
CalData: davResp.Responses[i].PropStat[0].Prop.CalendarData,
|
||||||
}
|
}
|
||||||
cal.Events = append(cal.Events, newEvent)
|
cal.Events = append(cal.Events, newEvent)
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-1
@@ -1,6 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ics "github.com/arran4/golang-ical"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
read_config()
|
read_config()
|
||||||
@@ -17,5 +22,18 @@ func main() {
|
|||||||
fmt.Printf("Cal %d is named %s\n", i, calDavData.Calandars[i].DisplayName)
|
fmt.Printf("Cal %d is named %s\n", i, calDavData.Calandars[i].DisplayName)
|
||||||
fmt.Printf("\tLink to cal: %s\n", calDavData.Calandars[i].Link)
|
fmt.Printf("\tLink to cal: %s\n", calDavData.Calandars[i].Link)
|
||||||
fmt.Printf("\tEvent count: %d\n", len(calDavData.Calandars[i].Events))
|
fmt.Printf("\tEvent count: %d\n", len(calDavData.Calandars[i].Events))
|
||||||
|
for j := range len(calDavData.Calandars[i].Events) {
|
||||||
|
cal, err := ics.ParseCalendar(strings.NewReader(calDavData.Calandars[i].Events[j].CalData))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(err.Error())
|
||||||
|
}
|
||||||
|
events := cal.Events()
|
||||||
|
for k := range len(events) {
|
||||||
|
name := events[k].GetProperty(ics.ComponentProperty(ics.PropertySummary)).Value
|
||||||
|
date, _ := events[k].GetStartAt()
|
||||||
|
fmt.Printf("\t\tEvent name: %s\n", name)
|
||||||
|
fmt.Printf("\t\t\tEvent date: %s\n", date.UTC().String())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user