Complete alpha newStations data, deactivate CORPUS Stations data

This commit is contained in:
Fred Boniface
2024-06-30 19:29:41 +01:00
parent 358e69bec7
commit fed0208291
5 changed files with 145 additions and 18 deletions

View File

@@ -1,19 +1,55 @@
package stations
import "fmt"
import (
"fmt"
"time"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
"git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
)
func Check() {
run()
oldMetadata, err := dbAccess.GetStationsMetadata()
if err != nil {
log.Error("Error reading Stations metadata", zap.Error(err))
}
if oldMetadata == nil {
log.Info("No old metadata for stations, rebuilding")
} else {
timeSinceLastUpdate := time.Since(oldMetadata.LastUpdate)
if timeSinceLastUpdate <= time.Hour*24*7 {
log.Info("Stations update not required")
return
}
}
ok := run()
if !ok {
log.Error("Error updating Stations data")
}
}
func run() {
func run() bool {
// Download
data, data2, err := download()
if err != nil {
fmt.Println(err)
return false
}
_, err = parseData(data, data2)
// Parse
stations, err := parseData(data, data2)
if err != nil {
fmt.Println(err)
return false
}
// Drop
dbAccess.DropCollection("stations")
// Push
dbAccess.PutManyNewStations(&stations)
return true
}