Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32d1192a3e | ||
|
|
549541c44f | ||
|
|
c2af7905cf |
@@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"rockhu-bot/local/api"
|
"rockhu-bot/local/api"
|
||||||
cronhu "rockhu-bot/local/utl/cron"
|
cronhu "rockhu-bot/local/utl/cron"
|
||||||
"rockhu-bot/local/utl/db"
|
"rockhu-bot/local/utl/db"
|
||||||
@@ -14,10 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
godotenv.Load()
|
||||||
if err != nil {
|
|
||||||
log.Fatal("error loading .env file")
|
|
||||||
}
|
|
||||||
di := dig.New()
|
di := dig.New()
|
||||||
|
|
||||||
cronhu.Init(di)
|
cronhu.Init(di)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func NewConcertRepository(db *gorm.DB) *ConcertRepository {
|
|||||||
func (as ConcertRepository) GetAll(ctx context.Context) *[]model.ConcertModel {
|
func (as ConcertRepository) GetAll(ctx context.Context) *[]model.ConcertModel {
|
||||||
db := as.db.WithContext(ctx)
|
db := as.db.WithContext(ctx)
|
||||||
ConcertModel := new([]model.ConcertModel)
|
ConcertModel := new([]model.ConcertModel)
|
||||||
db.Find(&ConcertModel)
|
db.Unscoped().Find(&ConcertModel)
|
||||||
return ConcertModel
|
return ConcertModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,11 @@ func (as ConcertService) CheckAndUpdateConcerts(ctx context.Context) []model.Con
|
|||||||
cm := as.GetAll(ctx)
|
cm := as.GetAll(ctx)
|
||||||
fmt.Printf("Currently there are %d concerts\n", len(*cm))
|
fmt.Printf("Currently there are %d concerts\n", len(*cm))
|
||||||
NewConcerts := scrapeData(ctx)
|
NewConcerts := scrapeData(ctx)
|
||||||
fmt.Printf("There are %d new concerts\n", len(*NewConcerts))
|
concertCount := len(*NewConcerts)
|
||||||
|
fmt.Printf("There are %d new concerts\n", concertCount)
|
||||||
|
if concertCount == 0 {
|
||||||
|
return *NewConcerts
|
||||||
|
}
|
||||||
forInsert, forDelete, _ := partitionConcerts(*cm, *NewConcerts)
|
forInsert, forDelete, _ := partitionConcerts(*cm, *NewConcerts)
|
||||||
|
|
||||||
tx := as.repository.CreateTransaction()
|
tx := as.repository.CreateTransaction()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package configs
|
package configs
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.1"
|
Version = "0.0.3"
|
||||||
Prefix = "v1"
|
Prefix = "v1"
|
||||||
Secret = "Donde4sta"
|
Secret = "Donde4sta"
|
||||||
SecretCode = "brasno"
|
SecretCode = "brasno"
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package cronhu
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"go.uber.org/dig"
|
"go.uber.org/dig"
|
||||||
@@ -9,8 +11,13 @@ import (
|
|||||||
|
|
||||||
func Init(di *dig.Container) *cron.Cron {
|
func Init(di *dig.Container) *cron.Cron {
|
||||||
|
|
||||||
c := cron.New()
|
location, err := time.LoadLocation(os.Getenv("TIMEZONE"))
|
||||||
err := di.Provide(func() *cron.Cron {
|
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("unable to load timezone!")
|
||||||
|
}
|
||||||
|
c := cron.New(cron.WithLocation(location))
|
||||||
|
err = di.Provide(func() *cron.Cron {
|
||||||
return c
|
return c
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user