event fetch for bwin
This commit is contained in:
parent
6d6b574c0b
commit
ec02497f97
|
|
@ -35,9 +35,10 @@ func (s *service) FetchLiveEvents(ctx context.Context) error {
|
|||
name string
|
||||
source string
|
||||
}{
|
||||
{"https://api.b365api.com/v1/bet365/inplay?sport_id=%d&token=%s", "bet365"},
|
||||
{"https://api.b365api.com/v1/bet365/inplay?sport_id=%d&&token=%s", "bet365"},
|
||||
{"https://api.b365api.com/v1/betfair/sb/inplay?sport_id=%d&token=%s", "betfair"},
|
||||
{"https://api.b365api.com/v1/1xbet/inplay?sport_id=%d&token=%s", "1xbet"},
|
||||
{"https://api.b365api.com/v1/bwin/inplay?sport_id=%d&token=%s", "bwin"},
|
||||
}
|
||||
|
||||
for _, url := range urls {
|
||||
|
|
@ -76,12 +77,14 @@ func (s *service) fetchLiveEvents(ctx context.Context, url, source string) error
|
|||
events := []domain.Event{}
|
||||
switch source {
|
||||
case "bet365":
|
||||
events = handleBet365prematch(body, sportID)
|
||||
events = handleBet365prematch(body, sportID, source)
|
||||
case "betfair":
|
||||
events = handleBetfairprematch(body, sportID, source)
|
||||
case "1xbet":
|
||||
// betfair and 1xbet have the same result structure
|
||||
events = handleBetfairprematch(body, sportID, source)
|
||||
case "bwin":
|
||||
events = handleBwinprematch(body, sportID, source)
|
||||
}
|
||||
|
||||
for _, event := range events {
|
||||
|
|
@ -98,7 +101,7 @@ func (s *service) fetchLiveEvents(ctx context.Context, url, source string) error
|
|||
|
||||
}
|
||||
|
||||
func handleBet365prematch(body []byte, sportID int) []domain.Event {
|
||||
func handleBet365prematch(body []byte, sportID int, source string) []domain.Event {
|
||||
var data struct {
|
||||
Success int `json:"success"`
|
||||
Results [][]map[string]interface{} `json:"results"`
|
||||
|
|
@ -106,7 +109,7 @@ func handleBet365prematch(body []byte, sportID int) []domain.Event {
|
|||
|
||||
events := []domain.Event{}
|
||||
if err := json.Unmarshal(body, &data); err != nil || data.Success != 1 {
|
||||
fmt.Printf(" Decode failed for sport_id=%d\nRaw: %s\n", sportID, string(body))
|
||||
fmt.Printf("%s: Decode failed for sport_id=%d\nRaw: %s\n", source, sportID, string(body))
|
||||
return events
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +138,7 @@ func handleBet365prematch(body []byte, sportID int) []domain.Event {
|
|||
Status: "live",
|
||||
MatchPeriod: getInt(ev["MD"]),
|
||||
AddedTime: getInt(ev["TA"]),
|
||||
Source: "bet365",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
events = append(events, event)
|
||||
|
|
@ -153,7 +156,7 @@ func handleBetfairprematch(body []byte, sportID int, source string) []domain.Eve
|
|||
|
||||
events := []domain.Event{}
|
||||
if err := json.Unmarshal(body, &data); err != nil || data.Success != 1 {
|
||||
fmt.Printf(" Decode failed for sport_id=%d\nRaw: %s\n", sportID, string(body))
|
||||
fmt.Printf("%s: Decode failed for sport_id=%d\nRaw: %s\n", source, sportID, string(body))
|
||||
return events
|
||||
}
|
||||
|
||||
|
|
@ -182,6 +185,42 @@ func handleBetfairprematch(body []byte, sportID int, source string) []domain.Eve
|
|||
return events
|
||||
}
|
||||
|
||||
func handleBwinprematch(body []byte, sportID int, source string) []domain.Event {
|
||||
var data struct {
|
||||
Success int `json:"success"`
|
||||
Results []map[string]interface{} `json:"results"`
|
||||
}
|
||||
|
||||
events := []domain.Event{}
|
||||
if err := json.Unmarshal(body, &data); err != nil || data.Success != 1 {
|
||||
fmt.Printf("%s: Decode failed for sport_id=%d\nRaw: %s\n", source, sportID, string(body))
|
||||
return events
|
||||
}
|
||||
|
||||
for _, ev := range data.Results {
|
||||
homeTeam := getString(ev["HomeTeam"])
|
||||
awayTeam := getString(ev["HomeTeam"])
|
||||
|
||||
event := domain.Event{
|
||||
ID: getString(ev["Id"]),
|
||||
SportID: fmt.Sprintf("%d", sportID),
|
||||
TimerStatus: "1",
|
||||
HomeTeam: homeTeam,
|
||||
AwayTeam: awayTeam,
|
||||
StartTime: time.Now().UTC().Format(time.RFC3339),
|
||||
LeagueID: getString(ev["LeagueId"]),
|
||||
LeagueName: getString(ev["LeagueName"]),
|
||||
IsLive: true,
|
||||
Status: "live",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
events = append(events, event)
|
||||
}
|
||||
|
||||
return events
|
||||
}
|
||||
|
||||
func (s *service) FetchUpcomingEvents(ctx context.Context) error {
|
||||
var wg sync.WaitGroup
|
||||
urls := []struct {
|
||||
|
|
@ -215,8 +254,8 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, url, sour
|
|||
for _, sportID := range sportIDs {
|
||||
for page <= totalPages {
|
||||
page = page + 1
|
||||
url := fmt.Sprintf("https://api.b365api.com/v1/bet365/upcoming?sport_id=%d&token=%s&page=%d", sportID, s.token, page)
|
||||
log.Printf("📡 Fetching data for event data page %d", page)
|
||||
url := fmt.Sprintf(url, sportID, s.token, page)
|
||||
log.Printf("📡 Fetching data from %s, for event data page %d", source, page)
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
log.Printf("❌ Failed to fetch event data for page %d: %v", page, err)
|
||||
|
|
@ -249,7 +288,7 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, url, sour
|
|||
if !slices.Contains(domain.SupportedLeagues, leagueID) {
|
||||
// fmt.Printf("⚠️ Skipping league %s (%d) as it is not supported\n", ev.League.Name, leagueID)
|
||||
skippedLeague = append(skippedLeague, ev.League.Name)
|
||||
continue
|
||||
// continue
|
||||
}
|
||||
|
||||
event := domain.UpcomingEvent{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user