Browse Source

Split out data fetching to function

master
Elis Hirwing 2 years ago
parent
commit
87e6ba7adf
Signed by: etu <elis@hirwing.se> GPG Key ID: D57EFA625C9A925F
1 changed files with 14 additions and 10 deletions
  1. +14
    -10
      src/statusscreen/SL.go

+ 14
- 10
src/statusscreen/SL.go View File

@@ -58,16 +58,7 @@ func (sl *SL) GetOutput() []string {

// Check if it's time to refresh yet
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.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
sl.getData()
}

for _, v := range sl.lastResponse.ResponseData.Metros {
@@ -89,6 +80,19 @@ func (sl *SL) GetOutput() []string {
return strings.Split(b.String(), "\n")
}

func (sl *SL) getData() {
// 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.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
}

func (sl *SL) getTimeTable() (SLResponse, error) {
parsedResponse := SLResponse{}



Loading…
Cancel
Save