fix schedule
This commit is contained in:
parent
a2c1d2fb15
commit
892a2a3827
|
@ -18,8 +18,8 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -33,24 +33,31 @@ var sport = sportAbbr("mlb")
|
||||||
func schedule(cmd *cobra.Command, args []string) {
|
func schedule(cmd *cobra.Command, args []string) {
|
||||||
sportId := int32(sportIDs[string(sport)])
|
sportId := int32(sportIDs[string(sport)])
|
||||||
|
|
||||||
client := api.NewAPIClient(api.NewConfiguration())
|
cfg := api.NewConfiguration()
|
||||||
|
cfg.Host = "statsapi.mlb.com"
|
||||||
|
cfg.Scheme = "https"
|
||||||
|
|
||||||
|
client := api.NewAPIClient(cfg)
|
||||||
req := client.ScheduleAPI.Schedule(context.Background())
|
req := client.ScheduleAPI.Schedule(context.Background())
|
||||||
|
|
||||||
req.SportId(sportId)
|
req = req.SportId(sportId)
|
||||||
req.TeamId(teamIDs[string(team)])
|
req = req.Date(date)
|
||||||
req.Date(date)
|
req = req.UsingPrivateEndpoint(false)
|
||||||
|
if team != "" {
|
||||||
|
req = req.TeamId(teamIDs[string(team)])
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := req.Execute()
|
resp, err := req.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(resp.Body)
|
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
// scheduleCmd represents the schedule command
|
// scheduleCmd represents the schedule command
|
||||||
|
|
Loading…
Reference in New Issue