From 76d063243d3dfe803f266dfda21fbc943006adb8 Mon Sep 17 00:00:00 2001 From: Topvennie Date: Sun, 11 Aug 2024 18:04:34 +0200 Subject: [PATCH 1/2] feat: show daily scans --- api/api.go | 5 ++- api/common.go | 40 +++++++++++++++++++++++ api/spotify.go | 22 +++++-------- api/tap.go | 56 ++++++++++---------------------- api/zess.go | 42 ++++++++++++++++++++++++ config/config.go | 12 +++++-- go.mod | 4 ++- go.sum | 20 ++++++------ screen/graph2.go | 23 -------------- screen/screen.go | 10 +++--- screen/tap.go | 34 +++++++++++++------- screen/zess.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ utils/utils.go | 55 ++++++++++++++++++-------------- 13 files changed, 275 insertions(+), 131 deletions(-) create mode 100644 api/common.go create mode 100644 api/zess.go delete mode 100644 screen/graph2.go create mode 100644 screen/zess.go diff --git a/api/api.go b/api/api.go index de9d251..fe8ad40 100644 --- a/api/api.go +++ b/api/api.go @@ -31,7 +31,10 @@ func Start(screenApp *screen.ScreenApp) { r.POST("/spotify", handlerWrapper(screenApp, spotifyGetMessage)) // Start Tap - go runTapRequests(screenApp) + go tapRunRequests(screenApp) + + // Start Zess + go zessRunRequests(screenApp) // Start API r.Run() diff --git a/api/common.go b/api/common.go new file mode 100644 index 0000000..15ce3ef --- /dev/null +++ b/api/common.go @@ -0,0 +1,40 @@ +package api + +import ( + "encoding/json" + "net/http" +) + +type header struct { + Key string + Value string +} + +var jsonHeader = header{ + "Accept", + "application/json", +} + +func makeGetRequest[T any](url string, headers []header, response *T) error { + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return err + } + + for _, header := range headers { + req.Header.Set(header.Key, header.Value) + } + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + if err := json.NewDecoder(resp.Body).Decode(response); err != nil { + return err + } + + return nil +} diff --git a/api/spotify.go b/api/spotify.go index 5b1b47a..1f24fd5 100644 --- a/api/spotify.go +++ b/api/spotify.go @@ -96,22 +96,16 @@ func spotifySetAccessToken() error { func spotifyGetTrackTitle(trackID string) (string, error) { url := fmt.Sprintf("https://api.spotify.com/v1/tracks/%s", trackID) - - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return "", err - } - req.Header.Set("Authorization", "Bearer "+spotifyAccessToken) - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return "", err + headers := []header{ + jsonHeader, + { + "Authorization", + "Bearer " + spotifyAccessToken, + }, } - defer resp.Body.Close() - trackResponse := &spotifyTrackResponse{} - if err := json.NewDecoder(resp.Body).Decode(trackResponse); err != nil { + + if err := makeGetRequest(url, headers, trackResponse); err != nil { return "", err } diff --git a/api/tap.go b/api/tap.go index da9f1ac..6bb8298 100644 --- a/api/tap.go +++ b/api/tap.go @@ -1,11 +1,10 @@ package api import ( - "encoding/json" "log" - "net/http" "scc/config" "scc/screen" + "slices" "time" ) @@ -14,51 +13,30 @@ type tapReponse struct { } var ( - tapURL = config.GetConfig().Tap.URL - timestampLayout = config.GetConfig().Tap.TimestampLayout - lastOrderTimestamp = time.Time{} + tapURL = config.GetConfig().Tap.URL + tapLastOrderTimestamp = time.Time{} ) -func runTapRequests(app *screen.ScreenApp) { - for true { - recentOrders, err := tapGetRecentOrders() - if err != nil { - log.Printf("Error: Unable to get recent order: %s\n", err) +func tapRunRequests(app *screen.ScreenApp) { + headers := []header{jsonHeader} + + for { + recentOrders := &tapReponse{} + if err := makeGetRequest(tapURL, headers, recentOrders); err != nil { + log.Printf("Error: Unable to get recent orders: %s\n", err) } - for _, order := range recentOrders.Orders { - timestamp, err := time.Parse(timestampLayout, order.OrderCreatedAt) - if err != nil { - log.Printf("Error: Unable to parse timestamp: %s\n", err) - } - if order.ProductCategory == "beverages" && timestamp.After(lastOrderTimestamp) { + slices.SortStableFunc(recentOrders.Orders, func(a, b screen.TapOrder) int { + return a.OrderCreatedAt.Compare(b.OrderCreatedAt) + }) + + for _, order := range recentOrders.Orders { + if order.OrderCreatedAt.After(tapLastOrderTimestamp) { app.Tap.Update(&order) - lastOrderTimestamp = timestamp + tapLastOrderTimestamp = order.OrderCreatedAt } } time.Sleep(1 * time.Minute) } } - -func tapGetRecentOrders() (*tapReponse, error) { - req, err := http.NewRequest("GET", tapURL, nil) - if err != nil { - return nil, err - } - req.Header.Set("Accept", "application/json") - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - response := &tapReponse{} - if err := json.NewDecoder(resp.Body).Decode(response); err != nil { - return nil, err - } - - return response, nil -} diff --git a/api/zess.go b/api/zess.go new file mode 100644 index 0000000..0f0777e --- /dev/null +++ b/api/zess.go @@ -0,0 +1,42 @@ +package api + +import ( + "log" + "scc/config" + "scc/screen" + "slices" + "time" +) + +type zessResponse struct { + Scans []screen.ZessScan `json:"scans"` +} + +var ( + zessURL = config.GetConfig().Zess.URL + zessLastOrderTimestamp = time.Time{} +) + +func zessRunRequests(app *screen.ScreenApp) { + headers := []header{jsonHeader} + + for { + recentScans := &zessResponse{} + if err := makeGetRequest(zessURL, headers, recentScans); err != nil { + log.Printf("Error: Unable to get recent scans: %s\n", err) + } + + slices.SortStableFunc(recentScans.Scans, func(a, b screen.ZessScan) int { + return a.ScanTime.Compare(b.ScanTime) + }) + + for _, order := range recentScans.Scans { + if order.ScanTime.After(zessLastOrderTimestamp) { + app.Zess.Update(&order) + zessLastOrderTimestamp = order.ScanTime + } + } + + time.Sleep(1 * time.Minute) + } +} diff --git a/config/config.go b/config/config.go index 60bc888..d54383c 100644 --- a/config/config.go +++ b/config/config.go @@ -20,15 +20,20 @@ type spotifyConfig struct { } type tapConfig struct { - URL string `yaml:"url"` - TimestampLayout string `yaml:"timestamp_layout"` - Beers []string `yaml:"beer"` + URL string `yaml:"url"` + Beers []string `yaml:"beer"` +} + +type zessConfig struct { + URL string `yaml:"url"` + DayAmount int `yaml:"day_amount"` } type Config struct { Cammie cammieConfig `yaml:"cammie"` Spotify spotifyConfig `yaml:"spotify"` Tap tapConfig `yaml:"tap"` + Zess zessConfig `yaml:"zess"` } var ( @@ -47,5 +52,6 @@ func GetConfig() *Config { log.Fatalf("Failed to unmarshal config: %v", err) } }) + return configInstance } diff --git a/go.mod b/go.mod index 36ba5ce..794f1ab 100644 --- a/go.mod +++ b/go.mod @@ -35,8 +35,10 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.23.0 // indirect golang.org/x/net v0.25.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/sys v0.21.0 // indirect golang.org/x/term v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect google.golang.org/protobuf v1.30.0 // indirect ) + +replace github.com/navidys/tvxwidgets => github.com/topvennie/tvxwidgets v0.7.2 diff --git a/go.sum b/go.sum index 0d31f70..8b2b6b0 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -56,12 +56,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/navidys/tvxwidgets v0.7.0 h1:ls5tikzqXnsHwAAV/8zwnRwx/DvSybepUih9txkwjwE= -github.com/navidys/tvxwidgets v0.7.0/go.mod h1:hzFnllDl4o2Ten/67T0F8ZgC1NiLrZYqWxLVjxWu+zo= -github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= -github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= -github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= -github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= +github.com/onsi/ginkgo/v2 v2.19.1 h1:QXgq3Z8Crl5EL1WBAC98A5sEBHARrAJNzAmMxzLcRF0= +github.com/onsi/ginkgo/v2 v2.19.1/go.mod h1:O3DtEWQkPa/F7fBMgmZQKKsluAy8pd3rEQdrjkPb9zA= +github.com/onsi/gomega v1.34.0 h1:eSSPsPNp6ZpsG8X1OVmOTxig+CblTc4AxpPBykhe2Os= +github.com/onsi/gomega v1.34.0/go.mod h1:MIKI8c+f+QLWk+hxbePD4i0LMJSExPaZOVfkoex4cAo= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -83,6 +81,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/topvennie/tvxwidgets v0.7.2 h1:pwO3zH7sAz423mNS3jN/5r0v6UCRlDeAnl+S50sZRVI= +github.com/topvennie/tvxwidgets v0.7.2/go.mod h1:/rHJ8G/5l5pF3QTHJhVAQoHlPjNSsd+eXeSA7Rg7rSs= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= @@ -115,8 +115,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= diff --git a/screen/graph2.go b/screen/graph2.go deleted file mode 100644 index 5471e03..0000000 --- a/screen/graph2.go +++ /dev/null @@ -1,23 +0,0 @@ -package screen - -import "github.com/rivo/tview" - -type Graph2 struct { - ScreenApp *ScreenApp - view *tview.Box -} - -func NewGraph2(screenApp *ScreenApp) *Graph2 { - graph2 := Graph2{ - ScreenApp: screenApp, - view: tview.NewBox().SetBorder(true).SetTitle("Graph 1"), - } - - return &graph2 -} - -func (graph1 *Graph2) Run() { -} - -func (graph1 *Graph2) Update(text string) { -} diff --git a/screen/screen.go b/screen/screen.go index 7c51300..216318b 100644 --- a/screen/screen.go +++ b/screen/screen.go @@ -14,7 +14,7 @@ type ScreenApp struct { Spotify *Spotify Cammie *Cammie Tap *Tap - Graph2 *Graph2 + Zess *Zess } // Execute a function with a lock @@ -33,7 +33,7 @@ func NewScreenApp() *ScreenApp { screen.Spotify = NewSpotify(&screen) screen.Cammie = NewCammie(&screen) screen.Tap = NewTap(&screen) - screen.Graph2 = NewGraph2(&screen) + screen.Zess = NewZess(&screen) // Build the screen layout screen.app.SetRoot(tview.NewFlex().SetDirection(tview.FlexRow). @@ -42,8 +42,8 @@ func NewScreenApp() *ScreenApp { AddItem(screen.Cammie.view, 0, 5, false). AddItem(tview.NewFlex().SetDirection(tview.FlexColumn). AddItem(screen.Tap.view, 0, 1, false). - AddItem(screen.Graph2.view, 0, 1, false), 0, 4, false), 0, 13, false), true). - EnableMouse(true) + AddItem(screen.Zess.view, 0, 1, false), 0, 4, false), 0, 13, false), true). + EnableMouse(false) return &screen } @@ -55,7 +55,7 @@ func Start(screen *ScreenApp) { go screen.Spotify.Run() go screen.Cammie.Run() go screen.Tap.Run() - go screen.Graph2.Run() + go screen.Zess.Run() // Start the screen application if err := screen.app.Run(); err != nil { diff --git a/screen/tap.go b/screen/tap.go index e26dd38..6c94d40 100644 --- a/screen/tap.go +++ b/screen/tap.go @@ -3,6 +3,7 @@ package screen import ( "scc/config" "strings" + "time" "github.com/gdamore/tcell/v2" "github.com/navidys/tvxwidgets" @@ -10,10 +11,10 @@ import ( ) type TapOrder struct { - OrderID int `json:"order_id"` - OrderCreatedAt string `json:"order_created_at"` - ProductName string `json:"product_name"` - ProductCategory string `json:"product_category"` + OrderID int `json:"order_id"` + OrderCreatedAt time.Time `json:"order_created_at"` + ProductName string `json:"product_name"` + ProductCategory string `json:"product_category"` } type Tap struct { @@ -26,6 +27,7 @@ var ( soft = 0 mate = 0 beer = 0 + food = 0 ) func NewTap(screenApp *ScreenApp) *Tap { @@ -40,9 +42,10 @@ func NewTap(screenApp *ScreenApp) *Tap { tap.bar.AddBar("Soft", 0, tcell.ColorBlue) tap.bar.AddBar("Mate", 0, tcell.ColorOrange) tap.bar.AddBar("Beer", 0, tcell.ColorRed) + tap.bar.AddBar("Food", 0, tcell.ColorGreen) tap.bar.SetAxesLabelColor(tcell.ColorWhite) - tap.view.AddItem(tap.bar, 0, 1, true) + tap.view.AddItem(tap.bar, 0, 1, false) return &tap } @@ -51,17 +54,26 @@ func (tap *Tap) Run() { } func (tap *Tap) Update(order *TapOrder) { + var label string + var value *int + switch { + case order.ProductCategory == "food": + label, value = "Food", &food + case order.ProductCategory != "beverages": + return case strings.Contains(order.ProductName, "Mate"): - mate++ - tap.bar.SetBarValue("Mate", mate) + label, value = "Mate", &mate case isBeer(order.ProductName): - beer++ - tap.bar.SetBarValue("Beer", beer) + label, value = "Beer", &beer default: - soft++ - tap.bar.SetBarValue("Soft", soft) + label, value = "Soft", &soft } + + *value++ + tap.ScreenApp.execute(func() { + tap.bar.SetBarValue(label, *value) + }) } func isBeer(productName string) bool { diff --git a/screen/zess.go b/screen/zess.go new file mode 100644 index 0000000..534bc7f --- /dev/null +++ b/screen/zess.go @@ -0,0 +1,83 @@ +package screen + +import ( + "scc/config" + "scc/utils" + "time" + + "github.com/gdamore/tcell/v2" + "github.com/navidys/tvxwidgets" + "github.com/rivo/tview" +) + +type ZessScan struct { + ID int `json:"id"` + ScanTime time.Time `json:"scan_time"` +} + +type Zess struct { + ScreenApp *ScreenApp + view *tview.Flex + chart *tvxwidgets.Plot +} + +var ( + scans = [][]float64{ + make([]float64, 0, config.GetConfig().Zess.DayAmount), + } + day = -1 +) + +func NewZess(screenApp *ScreenApp) *Zess { + zess := Zess{ + ScreenApp: screenApp, + view: tview.NewFlex(), + chart: tvxwidgets.NewPlot(), + } + + zess.view.SetBorder(true).SetTitle(" Zess ") + + zess.chart.SetBorder(false) + zess.chart.SetLineColor([]tcell.Color{tcell.ColorOrange}) + zess.chart.SetAxesLabelColor(tcell.ColorYellow) + zess.chart.SetAxesColor(tcell.ColorYellow) + zess.chart.SetMarker(tvxwidgets.PlotMarkerBraille) + zess.chart.SetDrawYAxisLabelFloat(false) + zess.chart.SetData(scans) + + zess.view.AddItem(zess.chart, 0, 1, false) + + return &zess +} + +func (zess *Zess) Run() { +} + +func (zess *Zess) Update(scan *ZessScan) { + if day == -1 { + scans[0] = append(scans[0], 0) + day = scan.ScanTime.YearDay() + } + + scanDay := scan.ScanTime.YearDay() + + if scanDay == day { + // Same day, increase the amount + scans[0][len(scans[0])-1]++ + } else { + // New day + + // Add the offset of days + dayDifference := utils.GetDayDifference(day, scan.ScanTime) - 1 + for i := 0; i < dayDifference; i++ { + scans[0] = utils.AddSliceElement(scans[0], 0) + } + + scans[0] = utils.AddSliceElement(scans[0], 1) + day = scanDay + } + + zess.ScreenApp.execute(func() { + zess.chart.SetData(scans) + }) +} diff --git a/utils/utils.go b/utils/utils.go index 3f8c5d8..4ce3637 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -2,40 +2,47 @@ package utils import ( "math/rand/v2" - "os" - "strconv" "time" ) -func GetEnv(key, defaultValue string) string { - if value := os.Getenv(key); value != "" { - return value - } - return defaultValue +func RandRange(min, max int) int { + return rand.IntN(max-min) + min } -func GetEnvAsInt(name string, defaultValue int) int { - valueStr := os.Getenv(name) - if value, err := strconv.Atoi(valueStr); err == nil { - return value - } - return defaultValue +func TimeAndDateFormat() string { + currentTime := time.Now() + formattedTime := currentTime.Format("15:04 02/01") + + return formattedTime +} + +func isLeapYear(year int) bool { + return (year%4 == 0 && year%100 != 0) || (year%400 == 0) } -func GetEnvAsBool(name string, defaultValue bool) bool { - valueStr := os.Getenv(name) - if value, err := strconv.ParseBool(valueStr); err == nil { - return value +func GetDayDifference(day1 int, date2 time.Time) int { + daysInYear := 365 + if isLeapYear(date2.Year()) { + daysInYear = 366 } - return defaultValue + + return (date2.YearDay() - day1 + daysInYear) % daysInYear } -func RandRange(min, max int) int { - return rand.IntN(max-min) + min +func ShiftSliceBackward[T any](slice []T) []T { + newSlice := make([]T, len(slice)-1, cap(slice)) + copy(newSlice, slice[1:]) + + return newSlice } -func TimeAndDateFormat() string { - currentTime := time.Now() - formattedTime := currentTime.Format("15:04 02/01") - return formattedTime +func AddSliceElement[T any](slice []T, element T) []T { + if len(slice) >= cap(slice) { + // Array is max size, shift everything + slice = ShiftSliceBackward(slice) + } + + slice = append(slice, element) + + return slice } From ab2f4a2e2e82b44f7759aa0f34d5eb08dac10c7c Mon Sep 17 00:00:00 2001 From: Topvennie Date: Sun, 11 Aug 2024 18:08:51 +0200 Subject: [PATCH 2/2] chore: update config --- config.example.yml | 27 +++++++++++++++++++++++++++ config.template.yaml | 16 +++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 config.example.yml diff --git a/config.example.yml b/config.example.yml new file mode 100644 index 0000000..1d4120a --- /dev/null +++ b/config.example.yml @@ -0,0 +1,27 @@ +cammie: + blocked_names: + - "Name 1" + - "Name 2" + blocked_ips: + - "10.0.0.10" + max_message_length: 200 +spotify: + client_id: "abcd" + client_secret: "dcba" +tap: + url: "https://tap.zeus.gent/recent" + beer: + - "Schelfaut" + - "Duvel" + - "Fourchette" + - "Jupiler" + - "Karmeliet" + - "Kriek" + - "Chouffe" + - "Maes" + - "Somersby" + - "Sportzot" + - "Stella" +zess: + url: "https://zess.zeus.gent/recent_scans" + day_amount: 40 diff --git a/config.template.yaml b/config.template.yaml index baf97ac..b6533df 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -1,7 +1,13 @@ cammie: - blocked_names: [] - blocked_ips: [] - max_message_length: + blocked_names: [] # List of names that don't get shown + blocked_ips: [] # List of IP's that don't get shown + max_message_length: # Max message list spotify: - client_id: - client_secret: + client_id: # Client ID of the Zeus spotify account + client_secret: # Client secret of the Zeus spotify account +tap: + url: # URL of tap + beer: [] # List of beers in tap, can be found in tap +zess: + url: # URL of zess + day_amount: # Amount of days to keep track, should be the same as is displayed which depends on the screen size