2024-03-21 05:34:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.lehouerou.net/laurent/sorare"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/spf13/cobra"
|
2024-05-23 04:18:54 +00:00
|
|
|
"github.com/uptrace/bun"
|
2024-03-21 05:34:38 +00:00
|
|
|
|
|
|
|
"git.lehouerou.net/laurent/sorarebuddy/cmd/common"
|
2024-05-23 04:18:54 +00:00
|
|
|
"git.lehouerou.net/laurent/sorarebuddy/db"
|
2024-03-21 17:57:17 +00:00
|
|
|
"git.lehouerou.net/laurent/sorarebuddy/sorare_utils"
|
2024-03-21 05:34:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2024-05-23 04:18:54 +00:00
|
|
|
dbconn, ok := ctx.Value(common.DbContextKey).(*bun.DB)
|
2024-03-21 05:34:38 +00:00
|
|
|
if !ok {
|
|
|
|
return errors.New("db not found in context")
|
|
|
|
}
|
|
|
|
|
2024-05-23 04:18:54 +00:00
|
|
|
us := sorare_utils.NewUpdateService(s, db.NewClient(dbconn))
|
|
|
|
err := us.UpdateLastClosedStartedAndOpenedFixtures(ctx)
|
2024-03-21 05:34:38 +00:00
|
|
|
if err != nil {
|
2024-05-23 04:18:54 +00:00
|
|
|
return errors.Wrap(err, "syncing database for last updated fixtures")
|
2024-03-21 05:34:38 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 04:18:54 +00:00
|
|
|
// 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")
|
|
|
|
// }
|
|
|
|
|
2024-03-21 05:34:38 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
}
|