resource-scraper/pkg/handler/prescene.go

47 lines
938 B
Go

package handler
import (
"fmt"
"log/slog"
"math"
"strconv"
"time"
"github.com/spf13/viper"
"git.amok.space/yevhen/resource-scraper/types/constant"
)
func (h *Handler) Prescene() string {
pagesToScrape := []string{"1"}
levels := viper.GetInt(constant.CfgKeyLevelsToScrape)
if levels > 1 {
var q = (60.0 / 100.0) * (100.0 / viper.GetFloat64(constant.CfgKeyLevelsToScrape))
minute := float64(time.Now().Minute())
if minute < 1 {
minute = 1
}
fmt.Printf("FLOAT: %f, %f, %v\n", minute, q, math.Ceil(minute/q))
hour := time.Now().Hour()
if hour == 1 {
hour = 25
} else if hour == 0 {
hour = 1
}
page := hour * int(math.Ceil(minute/q))
pagesToScrape = append(pagesToScrape, strconv.Itoa(page))
}
_, err := h.services.Prescene.GetPage(pagesToScrape)
if err != nil {
slog.Error("error occurred while getting page: ", "err", err.Error())
}
fmt.Printf("%+v\n", pagesToScrape)
return "ps"
}