40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package sorare_utils
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.lehouerou.net/laurent/sorare"
|
|
"git.lehouerou.net/laurent/sorare/football"
|
|
"git.lehouerou.net/laurent/sorare/graphql"
|
|
"github.com/pkg/errors"
|
|
"github.com/rs/zerolog/log"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
func GetGamesFromFixtures(
|
|
ctx context.Context,
|
|
s *sorare.Sorare,
|
|
fixtureSlugs []string,
|
|
) ([]football.Game, error) {
|
|
var games []football.Game
|
|
for _, slug := range fixtureSlugs {
|
|
log.Debug().Msgf("getting games for fixture %s...", slug)
|
|
g, err := s.Football.So5.FixtureGames(slug).Get(ctx, graphql.EmptyParams{})
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "getting games for fixture %s", slug)
|
|
}
|
|
log.Debug().Msgf("found %d games", len(g))
|
|
games = append(games, g...)
|
|
}
|
|
log.Debug().Msgf("found total of %d games before filtering", len(games))
|
|
games = lo.Filter(games, func(game football.Game, index int) bool {
|
|
return game.Id.Value != ""
|
|
})
|
|
log.Debug().Msgf("found total of %d games after filtering empty ids", len(games))
|
|
games = lo.UniqBy(games, func(game football.Game) string {
|
|
return game.Id.Value
|
|
})
|
|
log.Debug().Msgf("found total of %d games after filtering duplicate ids", len(games))
|
|
return games, nil
|
|
}
|