sorarebuddy/cmd/console/root.go
2024-05-23 08:18:54 +04:00

75 lines
1.8 KiB
Go

package main
import (
"git.lehouerou.net/laurent/sorare"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/uptrace/bun"
"git.lehouerou.net/laurent/sorarebuddy/cmd/common"
"git.lehouerou.net/laurent/sorarebuddy/db"
"git.lehouerou.net/laurent/sorarebuddy/sorare_utils"
)
var Cmd = &cobra.Command{
Use: "console",
Short: "console",
Long: `console`,
RunE: run,
PersistentPreRunE: common.CmdPreRunE,
}
func main() {
common.Start(Cmd)
}
func init() {
common.InitParams(Cmd)
}
func run(cmd *cobra.Command, _ []string) error {
//var wg conc.WaitGroup
ctx := cmd.Context()
s, ok := ctx.Value(common.SorareContextKey).(*sorare.Sorare)
if !ok {
return errors.New("sorare not found in context")
}
dbconn, ok := ctx.Value(common.DbContextKey).(*bun.DB)
if !ok {
return errors.New("db not found in context")
}
us := sorare_utils.NewUpdateService(s, db.NewClient(dbconn))
err := us.UpdateLastClosedStartedAndOpenedFixtures(ctx)
if err != nil {
return errors.Wrap(err, "syncing database for last updated fixtures")
}
// err := us.SyncStartedFixture(ctx)
// if err != nil {
// return errors.Wrap(err, "syncing database")
// }
// err := us.UpdatePlayers(ctx, []string{"joshua-kimmich", "leon-goretzka"})
// if err != nil {
// return errors.Wrap(err, "updating players")
// }
// err := us.UpdateAllPlayers(ctx)
// if err != nil {
// return errors.Wrap(err, "updating all players")
// }
// err := us.UpdateCurrentlyPlayingGames(ctx)
// if err != nil {
// return errors.Wrap(err, "initializing database")
// }
// log.Debug().Msg("start sequence completed. waiting for shutdown request")
// <-ctx.Done()
// log.Debug().Msg("shutdown requested")
// wg.Wait()
// log.Debug().Msg("shutdown complete")
return nil
}