alert at end of event too
parent
f1846ed93c
commit
aeb575e621
16
gcal.go
16
gcal.go
|
|
@ -24,8 +24,9 @@ func NewGCal() *GCal {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Name string
|
Name string
|
||||||
Time time.Time
|
Time time.Time
|
||||||
|
Duration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
|
func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
|
||||||
|
|
@ -60,9 +61,16 @@ func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
|
||||||
} else if t.After(tomorrow) {
|
} else if t.After(tomorrow) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var d time.Duration
|
||||||
|
if t2, err := time.Parse(time.RFC3339, events.Items[i].End.DateTime); err == nil {
|
||||||
|
d = t2.Sub(t)
|
||||||
|
}
|
||||||
|
|
||||||
result = append(result, Event{
|
result = append(result, Event{
|
||||||
Name: events.Items[i].Summary,
|
Name: events.Items[i].Summary,
|
||||||
Time: t,
|
Time: t,
|
||||||
|
Duration: d,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,13 @@ func TestGCal(t *testing.T) {
|
||||||
if err := gcal.Login(context.Background()); err != nil {
|
if err := gcal.Login(context.Background()); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
today, err := gcal.EventsToday(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
for i := range today {
|
||||||
|
t.Logf("[%d] %+v", i, today[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
main.go
8
main.go
|
|
@ -104,6 +104,14 @@ func alertsGCal(ctx context.Context) (chan string, error) {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
case ch <- events[0].Name:
|
case ch <- events[0].Name:
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
case <-time.After(events[0].Duration):
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
case ch <- "/" + events[0].Name:
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
events = events[1:]
|
events = events[1:]
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue