forked from hswaw/hscloud
hswaw/site: spaceapi: make the open state depend on members presence
Change-Id: Ibe5b25a989b06f757a696fc2c325695b6ad9d158 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1248 Reviewed-by: q3k <q3k@hackerspace.pl>
This commit is contained in:
parent
523df5c235
commit
f92437451c
1 changed files with 20 additions and 10 deletions
|
@ -2,11 +2,17 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"code.hackerspace.pl/hscloud/hswaw/site/calendar"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
const (
|
||||
openDayWeekday = time.Thursday
|
||||
openDayHour = 18
|
||||
)
|
||||
|
||||
// SpaceAPIResponse, per https://spaceapi.io/ - kinda. Mostly rewritten from
|
||||
// old implementation, someone should update this to use the official schema.
|
||||
type SpaceAPIResponse struct {
|
||||
|
@ -52,16 +58,10 @@ func generateSpaceAPIResponse(ctx context.Context) SpaceAPIResponse {
|
|||
state := SpaceAPIState{}
|
||||
state.Icon.Open = "https://static.hackerspace.pl/img/status-open-small.png"
|
||||
state.Icon.Closed = "https://static.hackerspace.pl/img/status-closed-small.png"
|
||||
// TODO(q3k): post-coronavirus, make automatically open based on calendar
|
||||
// events and Open Thursdays.
|
||||
open := false
|
||||
if open {
|
||||
state.Open = true
|
||||
state.Message = "open for public"
|
||||
} else {
|
||||
state.Open = false
|
||||
state.Message = "members only"
|
||||
}
|
||||
|
||||
location, _ := time.LoadLocation("Europe/Warsaw")
|
||||
now := time.Now().In(location)
|
||||
hour, _, _ := now.Clock()
|
||||
|
||||
peopleNowPresent := SpaceAPISensor{}
|
||||
atState, err := getAt(ctx)
|
||||
|
@ -75,6 +75,16 @@ func generateSpaceAPIResponse(ctx context.Context) SpaceAPIResponse {
|
|||
peopleNowPresent.Value = len(peopleNowPresent.Names)
|
||||
}
|
||||
|
||||
if peopleNowPresent.Value > 0 {
|
||||
state.Open = true
|
||||
}
|
||||
|
||||
if state.Open && now.Weekday() == openDayWeekday && hour >= openDayHour {
|
||||
state.Message = "open for public"
|
||||
} else {
|
||||
state.Message = "members only"
|
||||
}
|
||||
|
||||
res := SpaceAPIResponse{
|
||||
API: "0.13",
|
||||
Space: "Warsaw Hackerspace",
|
||||
|
|
Loading…
Reference in a new issue