|
|
|
@ -16,7 +16,7 @@ import (
|
|
|
|
|
type SL struct {
|
|
|
|
|
Config *Config
|
|
|
|
|
lastResponse SLResponse
|
|
|
|
|
lastRefresh int64
|
|
|
|
|
nextRefresh int64
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SLResponse is a struct to get the interesting data from API Responses
|
|
|
|
@ -56,18 +56,16 @@ func (sl *SL) GetOutput() string {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Check if it's time to refresh yet
|
|
|
|
|
if (sl.lastRefresh + sl.Config.SL.RefreshDelay) <= time.Now().Unix() {
|
|
|
|
|
// If it is, refresh
|
|
|
|
|
if sl.nextRefresh <= time.Now().Unix() {
|
|
|
|
|
// If it is, refresh the data
|
|
|
|
|
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)
|
|
|
|
|
sl.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
|
|
|
|
|
} else {
|
|
|
|
|
// log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|