parse events
This commit is contained in:
@@ -15,14 +15,12 @@ type PropStat struct {
|
||||
}
|
||||
|
||||
type Prop struct {
|
||||
DisplayName string `xml:"displayname"`
|
||||
Type ResourceType `xml:"resourcetype"`
|
||||
DisplayName string `xml:"displayname"`
|
||||
Type ResourceType `xml:"resourcetype"`
|
||||
CalendarData string `xml:"calendar-data"`
|
||||
}
|
||||
|
||||
type ResourceType struct {
|
||||
Collection *struct{} `xml:"DAV: collection"`
|
||||
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 {
|
||||
Link string
|
||||
CalData string
|
||||
}
|
||||
|
||||
type Calandar struct {
|
||||
@@ -95,19 +95,18 @@ const XML_cal string = `
|
||||
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<D:getetag/>
|
||||
<C:calendar-data/>
|
||||
</D:prop>
|
||||
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT"/>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
|
||||
</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 {
|
||||
req, _ := http.NewRequest(
|
||||
"REPORT",
|
||||
@@ -138,7 +137,7 @@ func get_calandar_data(cal Calandar, username string, password string) Calandar
|
||||
|
||||
for i := range len(davResp.Responses) {
|
||||
newEvent := Event{
|
||||
Link: serverConfig.URL + davResp.Responses[i].Href,
|
||||
CalData: davResp.Responses[i].PropStat[0].Prop.CalendarData,
|
||||
}
|
||||
cal.Events = append(cal.Events, newEvent)
|
||||
}
|
||||
|
||||
+19
-1
@@ -1,6 +1,11 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
ics "github.com/arran4/golang-ical"
|
||||
)
|
||||
|
||||
func main() {
|
||||
read_config()
|
||||
@@ -17,5 +22,18 @@ func main() {
|
||||
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("\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