diff --git a/src/statusscreen/Config.go b/src/statusscreen/Config.go index 10b921b..d591d80 100644 --- a/src/statusscreen/Config.go +++ b/src/statusscreen/Config.go @@ -4,7 +4,7 @@ package statusscreen type Config struct { SL struct { APIKey string - RefreshDelay int + RefreshDelay int64 SiteID int APIURL string } diff --git a/src/statusscreen/SL.go b/src/statusscreen/SL.go index 40a080c..9e56cf2 100644 --- a/src/statusscreen/SL.go +++ b/src/statusscreen/SL.go @@ -54,16 +54,20 @@ func (sl *SL) GetOutput() string { "Expcted", }) - sldata, err := sl.getTimeTable() - - // If no error occured, save the latest data to the struct - if err == nil { - sl.lastResponse = sldata - sl.lastRefresh = time.Now().Unix() - } + // Check if it's time to refresh yet + if (sl.lastRefresh + sl.Config.SL.RefreshDelay) <= time.Now().Unix() { + // If it is, refresh + sldata, err := sl.getTimeTable() + + // If no error occured, save the latest data to the struct + if err == nil { + sl.lastResponse = sldata + sl.lastRefresh = time.Now().Unix() + } - if err != nil { - log.Fatal(err) + if err != nil { + log.Fatal(err) + } } for _, v := range sl.lastResponse.ResponseData.Metros {