-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (65 loc) · 1.57 KB
/
Copy pathmain.go
File metadata and controls
73 lines (65 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"time"
)
// Game struct is created in purpose of demonstration of SoccerScraper function.
// More deteiled struct can be obtained from source.
type Game struct {
MatchName string
StartTime time.Time
Team1Name string
Team2Name string
WinTeam1 string
WinTeam2 string
Draw string
IsSuspended bool
}
// SoccerScraper pars only soccer/league pages on web www.ladbrokes.com.au
func examle(data Soccer) ([]Game, error) {
var game Game
gameSlice := make([]Game, len(data.Pay[0].Rows.Soccer.League.Matches))
a := data.Pay[0].Rows.Soccer.League.Category
for i, b := range data.Pay[0].Rows.Soccer.League.Matches {
game.MatchName = a + ": " + b.Description
game.Team1Name = b.Competitors[0].Name
game.Team2Name = b.Competitors[1].Name
if b.IsSuspended {
game.WinTeam1 = "SUS"
game.WinTeam2 = "SUS"
game.Draw = "SUS"
} else {
game.WinTeam1 = b.Competitors[0].Win
game.WinTeam2 = b.Competitors[1].Win
game.Draw = b.Draw
}
game.IsSuspended = b.IsSuspended
t, err := time.Parse(time.RFC1123Z, b.OutcomeDateTime)
if err != nil {
return nil, err
}
game.StartTime = t
gameSlice[i] = game
}
return gameSlice, nil
}
func main() {
m, err := SoccerScraper("https://www.ladbrokes.com.au/sports/soccer/69616684-football-australia-australian-a-league/")
if err != nil {
panic(err)
}
matches, err := examle(m)
if err != nil {
panic(err)
}
for _, m := range matches {
p := fmt.Println
p(m.MatchName)
p(m.Team1Name)
p(m.Team2Name)
p(m.WinTeam1)
p(m.WinTeam2)
p(m.Draw)
p(m.StartTime)
}
}