Complete alpha newStations data, deactivate CORPUS Stations data
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user