package flashscore import ( "bytes" "fmt" "os" "strings" "github.com/PuerkitoBio/goquery" // xhtml "golang.org/x/net/html" //"strings" "encoding/json" "testing" ) /* func TestParseFootballZoneAndChamp(t *testing.T) { var src = []byte(`ENGLAND - SERIA A - DIVISION 1: Premier League - Round 30
`) doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(src)) if err != nil { t.Fatal(err) } zone, champ, home, away, err := parseTeamMatchInfo(doc, Football) if err != nil { t.Fatal(err) } fmt.Printf("zone: %s\n", zone.Name) fmt.Printf("zoneID: %s\n\n", zone.ZoneID) fmt.Printf("champ.ChampID: %s\n", champ.ChampID) fmt.Printf("champ.Name: %v\n", champ.Name) fmt.Printf("champ.ZoneID: %v\n\n", champ.ZoneID) fmt.Printf("home.CanonicalName: %s\n", home.CanonicalName) fmt.Printf("home.TeamID: %s\n", home.TeamID) fmt.Printf("home.ZoneID: %s\n\n", home.ZoneID) fmt.Printf("away.CanonicalName: %s\n", away.CanonicalName) fmt.Printf("away.TeamID: %s\n", away.TeamID) fmt.Printf("away.ZoneID: %s\n", away.ZoneID) } */ //var reChampName = regexp.MustCompile(`([^])`) func TestTeamZone(t *testing.T) { var teamZone = []byte(`

Football England

`) doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(teamZone)) if err != nil { t.Fatal(err) } zone, err := parseZoneOnTeamPage(doc, Football) if err != nil { t.Fatal(err) } fmt.Printf("zone.ZoneID: %s\nzone.Name: %s\n", zone.ZoneID, zone.Name) } func TestFullTimeTotalOdds(t *testing.T) { var src = []byte(`
Bookmaker Total Over Under
 
0.5 1.09 5.90
 
0.5 1.11 6.50
Bookmaker Total Over Under
 
2.5 2.91 1.52
 
2.5 2.75 1.44
2.5 2.38 1.53
`) doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(src)) if err != nil { t.Fatal(err) } odds, err := parseOddsTotal(doc) if err != nil { t.Fatal(err) } buf, _ := json.MarshalIndent(odds, "", " ") fmt.Printf("Total odds: %s\n", buf) } //
 
3.24 3.50 2.37
 
2.24 5.50 5.37
`) doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(oddssrc)) if err != nil { t.Fatal(err) } table1x2Odds := doc.Find("#odds_1x2") offers, err := parseOdds1x2(table1x2Odds) if err != nil { t.Fatal(err) } buf, _ := json.MarshalIndent(offers, "", " ") fmt.Printf("%s\n", buf) } func TestParseNextRoundFixtures(t *testing.T) { /* var handballSchedule = `` Postponed: (разные чемпионаты) ~AA÷6R6Qjxol ¬AD÷1602514800 ¬ADE÷1602514800 ¬AB÷3 ¬CR÷3 ¬AC÷4 ¬CX÷Butel Skopje ¬RW÷0 ¬AX÷0 ¬BX÷-1 ¬WQ÷ ¬WN÷TIK ¬AF÷Tikvesh ¬JB÷M10TCQre ¬WV÷tikvesh ¬WM÷BUT ¬AE÷Butel Skopje ¬JA÷rB1PD6Tl ¬WU÷butel-skopje¬ ~AA÷CzK7rvtg ¬AD÷1602531000 ¬ADE÷1602531000 ¬AB÷3 ¬CR÷3 ¬AC÷4 ¬CX÷FH Hafnarfjordur ¬RW÷0 ¬AX÷0 ¬BX÷-1 ¬WQ÷ ¬WN÷GRO ¬AF÷Grotta ¬JB÷06YZR1Pr ¬WV÷grotta ¬WM÷FHH ¬AE÷FH Hafnarfjordur ¬JA÷bcn8WsHR ¬WU÷fh-hafnarfjordur ¬AM÷Postponed due to safety reasons.¬ Normal: ~AA÷MyARroUi ¬AD÷1602520200 ¬ADE÷1602520200 ¬AB÷1 ¬CR÷1 ¬AC÷1 ¬CX÷Ribe-Esbjerg ¬RW÷0 ¬AX÷0 ¬BX÷-1 ¬WQ÷ ¬WM÷RIB ¬AE÷Ribe-Esbjerg ¬JA÷xrSUrVlt ¬WU÷ribe-esbjerg ¬WN÷FRE ¬AF÷Fredericia ¬JB÷lIVYsk4n ¬WV÷fredericia ¬AN÷n ¬MW÷417|453|455|512|471¬ ~AA÷xMZpVA2J ¬AD÷1602522000 ¬ADE÷1602522000 ¬AB÷1 ¬CR÷1 ¬AC÷1 ¬CX÷Redbergslids ¬RW÷0 ¬AX÷0 ¬BX÷-1 ¬WQ÷ ¬WN÷SKO ¬AF÷Skovde ¬JB÷AyzHGCHi ¬WV÷skovde ¬WM÷RED ¬AE÷Redbergslids ¬JA÷dYVCHh2o ¬WU÷redbergslids ¬AL÷{"2":[{"BU":"\/bookmaker\/16\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-16.png","BN":"bet365","BI":16,"BT":"GEO restrictions apply. Funded account required or to have placed a bet in the last 24 hours. GamblingTherapy.org. 18+"},{"BU":"\/bookmaker\/539\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-539.png","BN":"Betclic.pl","BI":539},{"BU":"\/bookmaker\/45\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-45.png","BN":"Chance","BI":45},{"BU":"\/bookmaker\/165\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-165.png","BN":"STS.pl","BI":165},{"BU":"\/bookmaker\/49\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-49.1.png","BN":"Tipsport","BI":49},{"BU":"\/bookmaker\/411\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-411.1.png","BN":"Tipsport SK","BI":411},{"BU":"\/bookmaker\/454\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-454.png","BN":"Winlinebet","BI":454},{"BU":"\/bookmaker\/523\/?from=live-streaming&sport=0","IU":"\/res\/image\/data\/bookmakers\/17-523.png","BN":"Wplay","BI":523}]} ¬AN÷y ¬MW÷16|417|392|419|453|454|455|49|45|33|165|539|544|38|512|508|24|27|471|411|43|507|549¬ res, err := parseNextRoundFixtures(handballSchedule) if err != nil { t.Fatal(err) } for _, m := range res.Matches { fmt.Printf("%s: %s\n", m.StartTime, m.MatchID) } */ } /* func TestListScheduledHandballMatches(t *testing.T) { result, err := listScheduledHandballMatches() if err != nil { t.Fatal(err) } for _, m := range result { fmt.Printf("%s: %s\n", m.StartTime, m.MatchID) } } func TestGetUpcomingHandballMatchReport(t *testing.T) { report, err := GetUpcomingMatchReport("MyARroUi") if err != nil { t.Fatal(err) } buf, _ := json.MarshalIndent(report, "", " ") fmt.Printf("%s\n\n", buf) //for _, m := range result { // /fmt.Printf("%s: %s\n", time.Unix(m.StartTime, 0), m.MatchID) // } */ // HANDBALL func TestParseHandballOdds(t *testing.T) { // Строку возвращает отдельный запрос на адрес handballOddsURL // flashscore format buf, err := os.ReadFile("for_parse/oddsHandball.fsf") if err != nil { t.Fatal(err) } str := string(buf) odds, err := parseFlashscoreEncodedOdds(str) if err != nil { t.Fatal(err) } buf, _ = json.MarshalIndent(odds, "", " ") fmt.Printf("%s\n\n", buf) } func TestParseHandballH2H(t *testing.T) { // flashscore format buf, err := os.ReadFile("for_parse/h2hHandball.fsf") if err != nil { t.Fatal(err) } str := string(buf) homeTeamName := "HSG Wetzlar" awayTeamName := "MT Melsungen" homeTeamMatches, awayTeamMatches, h2hMatches, err := parseFlashscoreEncodedH2H(str, homeTeamName, awayTeamName) if err != nil { t.Fatal(err) } buf, _ = json.MarshalIndent(homeTeamMatches, "", " ") fmt.Printf("HomeTeamMatches:\n%s\n\n", buf) buf, _ = json.MarshalIndent(awayTeamMatches, "", " ") fmt.Printf("AwayTeamMatches:\n%s\n\n", buf) buf, _ = json.MarshalIndent(h2hMatches, "", " ") fmt.Printf("h2hMatches:\n%s\n\n", buf) } func TestParseAllGames(t *testing.T) { // flashscore format buf, err := os.ReadFile("for_parse/allGamesFootball.fsf") //buf, err := os.ReadFile("for_parse/allGamesHandball.fsf") if err != nil { t.Fatal(err) } str := string(buf) /* list, err := ParseFlashscoreEncoding(str) if err != nil { t.Fatal(err) } for _,m := range list { for k, v := range m { fmt.Printf("%s: %s\n", k, v) } fmt.Println() } */ matches, err := parseFlashscoreEncodedAllGames(str, Football) //matches, err := parseFlashscoreEncodedAllGames(str, Handball) if err != nil { t.Fatal(err) } buf, _ = json.MarshalIndent(matches, "", " ") fmt.Printf("%s\n\n", buf) } func TestParseChampNameOnChampPage(t *testing.T) { buf := []byte(`

Football Germany

Bundesliga
2020/2021
`) doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(buf)) if err != nil { t.Fatal(err) } // First - f := doc.Find("div.teamHeader__name").First() //.Children() txt := f.Text() txt = strings.TrimSpace(txt) champID := "/football/germany/bundesliga" parts := strings.Split(champID, "/") zoneID := strings.Join(parts[:3], "/") fmt.Printf("%q\n\n%q\n\n", txt, zoneID) //f := doc.Find("h2.tournament").First() } func TestParseEnvironmentJsVarOnMatchPageInJsVar(t *testing.T) { // flashscore format buf, err := os.ReadFile("for_parse/environmentJsVarOnMatchPage.html") if err != nil { t.Fatal(err) } doc, err := goquery.NewDocumentFromReader(bytes.NewBuffer(buf)) if err != nil { t.Fatal(err) } home, away, err := parseTeamsOnMatchPageInJsVar(doc) if err != nil { t.Fatal(err) } buf, _ = json.MarshalIndent(home, "", " ") fmt.Printf("%s\n\n", buf) buf, _ = json.MarshalIndent(away, "", " ") fmt.Printf("%s\n\n", buf) }