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>
diff --git a/hswaw/site/spaceapi.go b/hswaw/site/spaceapi.go
index 13c5aad..134c4d3 100644
--- a/hswaw/site/spaceapi.go
+++ b/hswaw/site/spaceapi.go
@@ -2,11 +2,17 @@
 
 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 @@
 	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 @@
 		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",