Add fetching .ical file and sending a message about the next event
This commit is contained in:
parent
c868f76681
commit
54f5b7e20e
1
.gitignore
vendored
1
.gitignore
vendored
@ -22,3 +22,4 @@
|
||||
go.work
|
||||
|
||||
config.ini
|
||||
event-bot
|
||||
|
20
go.sum
Normal file
20
go.sum
Normal file
@ -0,0 +1,20 @@
|
||||
github.com/ChannelMeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 h1:N5Vqww5QISEHsWHOWDEx4PzdIay3Cg0Jp7zItq2ZAro=
|
||||
github.com/ChannelMeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61/go.mod h1:GnKXcK+7DYNy/8w2Ex//Uql4IgfaU82Cd5rWKb7ah00=
|
||||
github.com/apognu/gocal v0.9.1 h1:e3vlb+YV5wXvqBxYsC6GvkuUAEnRipkvoA1P79gwspM=
|
||||
github.com/apognu/gocal v0.9.1/go.mod h1:5tNvJsQGJHwS3KqWxHAFZzavC4k42jrJ3ouVmOzS/AM=
|
||||
github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61 h1:o64h9XF42kVEUuhuer2ehqrlX8rZmvQSU0+Vpj1rF6Q=
|
||||
github.com/channelmeter/iso8601duration v0.0.0-20150204201828-8da3af7a2a61/go.mod h1:Rp8e0DCtEKwXFOC6JPJQVTz8tuGoGvw6Xfexggh/ed0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/xmppo/go-xmpp v0.2.6 h1:FYtKhjLF3tberIN4oDVjMvyWPrzvnV250BxAgPbkjzo=
|
||||
github.com/xmppo/go-xmpp v0.2.6/go.mod h1:qwEZKhH+DtYMyJpjpRBKe5b2uMzlbQ3yGw26p3vzzkw=
|
||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
|
||||
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
33
main.go
33
main.go
@ -1,14 +1,43 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitea.dmz.rs/txrpe/event-bot/chatbot"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gitea.dmz.rs/txrpe/event-bot/chatbot"
|
||||
"github.com/apognu/gocal"
|
||||
)
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("https://dmz.rs/events.ical")
|
||||
if err != nil {
|
||||
// handle err
|
||||
// todo add log
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
cal := gocal.NewParser(resp.Body)
|
||||
|
||||
start, end := time.Now(), time.Now().Add(24*time.Hour)
|
||||
cal.Start = &start
|
||||
cal.End = &end
|
||||
|
||||
cal.Parse()
|
||||
if len(cal.Events) == 0 {
|
||||
// Maybe change this to some kind of logs
|
||||
fmt.Printf("No events today :(")
|
||||
return
|
||||
}
|
||||
|
||||
e := cal.Events[0]
|
||||
message := fmt.Sprint("Veceras u decentrali:\n", e.Summary, "\n", e.URL, "\n", e.Location, " ", e.Start.Format(time.Kitchen))
|
||||
|
||||
nkbot, err := chatbot.NewEventBot()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
nkbot.SendMessage("Cao svete")
|
||||
nkbot.SendMessage(message)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user