make it build again
This commit is contained in:
parent
934db53dad
commit
4f1114f297
|
@ -28,12 +28,14 @@ import (
|
||||||
|
|
||||||
func content(cmd *cobra.Command, args []string) {
|
func content(cmd *cobra.Command, args []string) {
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
client := api.NewAPIClient(api.NewConfiguration())
|
||||||
content, _, err := client.GameApi.Content(context.Background(), gamePk, nil)
|
req := client.GameAPI.Content(context.Background(), gamePk)
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(content)
|
json, err := json.Marshal(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,14 @@ import (
|
||||||
|
|
||||||
func feed(cmd *cobra.Command, args []string) {
|
func feed(cmd *cobra.Command, args []string) {
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
client := api.NewAPIClient(api.NewConfiguration())
|
||||||
standing, _, err := client.GameApi.LiveGameV1(context.Background(), gamePk, nil)
|
req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(standing)
|
json, err := json.Marshal(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/antihax/optional"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"scm.dairydemon.net/filifa/mlbstats/api"
|
"scm.dairydemon.net/filifa/mlbstats/api"
|
||||||
)
|
)
|
||||||
|
@ -32,26 +31,21 @@ var team teamAbbr
|
||||||
var sport = sportAbbr("mlb")
|
var sport = sportAbbr("mlb")
|
||||||
|
|
||||||
func schedule(cmd *cobra.Command, args []string) {
|
func schedule(cmd *cobra.Command, args []string) {
|
||||||
var teamIds []int32
|
|
||||||
if team != "" {
|
|
||||||
teamIds = append(teamIds, int32(teamIDs[string(team)]))
|
|
||||||
}
|
|
||||||
|
|
||||||
sportId := int32(sportIDs[string(sport)])
|
sportId := int32(sportIDs[string(sport)])
|
||||||
|
|
||||||
opts := api.ScheduleApiScheduleOpts{
|
|
||||||
TeamId: optional.NewInterface(teamIds),
|
|
||||||
SportId: optional.NewInterface([]int32{sportId}),
|
|
||||||
Date: optional.NewString(date),
|
|
||||||
}
|
|
||||||
|
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
client := api.NewAPIClient(api.NewConfiguration())
|
||||||
sched, _, err := client.ScheduleApi.Schedule(context.Background(), false, &opts)
|
req := client.ScheduleAPI.Schedule(context.Background())
|
||||||
|
|
||||||
|
req.SportId(sportId)
|
||||||
|
req.TeamId(teamIDs[string(team)])
|
||||||
|
req.Date(date)
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(sched)
|
json, err := json.Marshal(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/antihax/optional"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"scm.dairydemon.net/filifa/mlbstats/api"
|
"scm.dairydemon.net/filifa/mlbstats/api"
|
||||||
"scm.dairydemon.net/filifa/mlbstats/api/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var league leagueAbbr
|
var league leagueAbbr
|
||||||
|
@ -34,17 +32,17 @@ func standings(cmd *cobra.Command, args []string) {
|
||||||
var leagueIds []int32
|
var leagueIds []int32
|
||||||
leagueIds = append(leagueIds, int32(leagueIDs[string(league)]))
|
leagueIds = append(leagueIds, int32(leagueIDs[string(league)]))
|
||||||
|
|
||||||
opts := api.StandingsApiStandings1Opts{
|
|
||||||
LeagueId: optional.NewInterface(leagueIds),
|
|
||||||
}
|
|
||||||
|
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
client := api.NewAPIClient(api.NewConfiguration())
|
||||||
standing, _, err := client.StandingsApi.Standings1(context.Background(), string(models.REGULAR_SEASON_StandingsType), &opts)
|
req := client.StandingsAPI.Standings1(context.Background(), "regularSeason")
|
||||||
|
|
||||||
|
req.LeagueId(leagueIDs[string(league)])
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(standing)
|
json, err := json.Marshal(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,24 +20,23 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/antihax/optional"
|
|
||||||
"github.com/evanphx/json-patch/v5"
|
"github.com/evanphx/json-patch/v5"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"scm.dairydemon.net/filifa/mlbstats/api"
|
"scm.dairydemon.net/filifa/mlbstats/api"
|
||||||
"scm.dairydemon.net/filifa/mlbstats/api/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var gamePk int32
|
var gamePk int32
|
||||||
|
|
||||||
func extractPatches(resp string) ([]jsonpatch.Patch, error) {
|
func extractPatches(resp []byte) ([]jsonpatch.Patch, error) {
|
||||||
var patches []jsonpatch.Patch
|
var patches []jsonpatch.Patch
|
||||||
|
|
||||||
var objs []map[string]jsonpatch.Patch
|
var objs []map[string]jsonpatch.Patch
|
||||||
err := json.Unmarshal([]byte(resp), &objs)
|
err := json.Unmarshal(resp, &objs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return patches, err
|
return patches, err
|
||||||
}
|
}
|
||||||
|
@ -50,12 +49,26 @@ func extractPatches(resp string) ([]jsonpatch.Patch, error) {
|
||||||
return patches, err
|
return patches, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func patch(feed *models.BaseballGameRestObject, client *api.APIClient) error {
|
func patch(body []byte, client *api.APIClient) error {
|
||||||
opts := api.GameApiLiveGameDiffPatchV1Opts{
|
var v any
|
||||||
StartTimecode: optional.NewString(feed.MetaData.TimeStamp),
|
err := json.Unmarshal(body, &v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
diffPatch, _, err := client.GameApi.LiveGameDiffPatchV1(context.Background(), feed.GamePk, &opts)
|
vobj := v.(map[string]any)
|
||||||
|
metaData := vobj["metaData"].(map[string]any)
|
||||||
|
timestamp := metaData["timeStamp"]
|
||||||
|
|
||||||
|
req := client.GameAPI.LiveGameDiffPatchV1(context.Background(), gamePk)
|
||||||
|
req.StartTimecode(timestamp)
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
diffPatch, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -65,19 +78,13 @@ func patch(feed *models.BaseballGameRestObject, client *api.APIClient) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
enc, err := json.Marshal(feed)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, patch := range patches {
|
for _, patch := range patches {
|
||||||
enc, err = patch.Apply(enc)
|
body, err = patch.Apply(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(enc, &feed)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,24 +100,29 @@ func newWebsocket(gamePk int32) (*gamedayWebsocket, <-chan error, error) {
|
||||||
return ws, ch, err
|
return ws, ch, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleUnexpectedClose(feed *models.BaseballGameRestObject, client *api.APIClient) (*gamedayWebsocket, error) {
|
func handleUnexpectedClose(body []byte, client *api.APIClient) (*gamedayWebsocket, error) {
|
||||||
ws, _, err := newWebsocket(feed.GamePk)
|
ws, _, err := newWebsocket(gamePk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
newFeed, _, err := client.GameApi.LiveGameV1(context.Background(), feed.GamePk, nil)
|
req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
|
||||||
*feed = newFeed
|
resp, err := req.Execute()
|
||||||
|
if err != nil {
|
||||||
|
return ws, err
|
||||||
|
}
|
||||||
|
|
||||||
|
body, err = io.ReadAll(resp.Body)
|
||||||
return ws, err
|
return ws, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateFeed(feed *models.BaseballGameRestObject, ws *gamedayWebsocket, client *api.APIClient) error {
|
func updateFeed(body []byte, ws *gamedayWebsocket, client *api.APIClient) error {
|
||||||
var p push
|
var p push
|
||||||
err := ws.ReadJSON(&p)
|
err := ws.ReadJSON(&p)
|
||||||
if websocket.IsUnexpectedCloseError(err, GameFinalCode, GameUnavailableCode) {
|
if websocket.IsUnexpectedCloseError(err, GameFinalCode, GameUnavailableCode) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
||||||
newWs, err := handleUnexpectedClose(feed, client)
|
newWs, err := handleUnexpectedClose(body, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -121,14 +133,18 @@ func updateFeed(feed *models.BaseballGameRestObject, ws *gamedayWebsocket, clien
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = patch(feed, client)
|
err = patch(body, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
newFeed, _, err := client.GameApi.LiveGameV1(context.Background(), feed.GamePk, nil)
|
req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
*feed = newFeed
|
body, err = io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -142,20 +158,22 @@ func subscribe(cmd *cobra.Command, args []string) {
|
||||||
defer ws.Close()
|
defer ws.Close()
|
||||||
|
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
client := api.NewAPIClient(api.NewConfiguration())
|
||||||
feed, _, err := client.GameApi.LiveGameV1(context.Background(), gamePk, nil)
|
req := client.GameAPI.LiveGameV1(context.Background(), gamePk)
|
||||||
|
|
||||||
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
json, err := json.Marshal(feed)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(json))
|
fmt.Println(string(body))
|
||||||
|
|
||||||
err = updateFeed(&feed, ws, client)
|
err = updateFeed(body, ws, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue