-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonicballroom.go
69 lines (61 loc) · 1.82 KB
/
sonicballroom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"time"
"github.com/arran4/golang-ical"
)
func init() {
RegisterAdapter("sonicballroom", sonicballroomUrl, "Live music bar in Cologne (beta)", sonicballroomAdapter)
}
const (
sonicballroomUrl = "https://www.sonic-ballroom.de/"
sonicballroomSrc = "https://api.loveyourartist.com/v1/store/events?filter[profiles][$eq]=5ed76651ff8ee32c0749e103&filter[endAt][$gte]=%d"
sonicballroomEventUrl = "https://loveyourartist.com/de/events/%s"
)
type sonicballroomEvent struct {
Id string `json:"id"`
Name string `json:"name"`
PublishedAt time.Time `json:"publishedAt"`
StartAt time.Time `json:"startAt"`
EndAt time.Time `json:"endAt"`
Slug string `json:"slug"`
}
func sonicballroomAdapter(w io.Writer) error {
now := time.Now()
res, err := http.Get(fmt.Sprintf(sonicballroomSrc, now.Truncate(240*time.Hour).UnixMilli()))
if err != nil {
return err
}
defer res.Body.Close()
var events []sonicballroomEvent
err = json.NewDecoder(res.Body).Decode(&events)
if err != nil {
return err
}
cal := ics.NewCalendarFor("github.com/cbix/ics")
cal.SetName("Sonic Ballroom")
cal.SetUrl(sonicballroomUrl)
cal.SetTimezoneId("Europe/Berlin")
lastModified := time.Time{}
for _, ev := range events {
event := cal.AddEvent(fmt.Sprintf("%[email protected]", ev.Id))
event.SetDtStampTime(now)
event.SetSummary(ev.Name)
event.SetLocation("Sonic Ballroom")
event.SetStartAt(ev.StartAt)
event.SetEndAt(ev.EndAt)
event.SetURL("https://loveyourartist.com/de/events/" + ev.Slug)
event.SetCreatedTime(ev.PublishedAt)
event.SetModifiedAt(ev.PublishedAt)
if ev.PublishedAt.After(lastModified) {
lastModified = ev.PublishedAt
}
}
if !lastModified.IsZero() {
cal.SetLastModified(lastModified)
}
return cal.SerializeTo(w)
}