-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrounds.go
102 lines (75 loc) · 1.77 KB
/
rounds.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"github.com/urfave/cli"
"fmt"
"os"
"encoding/json"
"github.com/olekukonko/tablewriter"
"time"
"strconv"
)
func ListRounds(c *cli.Context) {
results := APIResponse{}
res, err := GetJson(API.GetFeed)
if err != nil {
fmt.Println("Something went wrong : " + err.Error())
os.Exit(2)
}
err = json.Unmarshal(res, &results)
if err != nil {
fmt.Println("Something went wrong : " + err.Error())
os.Exit(2)
}
dateFilter := c.String("date")
table := tablewriter.NewWriter(c.App.Writer)
table.SetHeader([]string{
"EVENT",
"DATE",
"GROUP",
"HOME",
"HOME SCORERS",
"AWAY",
"AWAY SCORERS",
"STADIUM"})
for _, round := range results.Rounds {
for _, match := range round.Matches {
if dateFilter == "" {
table.Append(ParseMatch(round, match))
} else {
if dateFilter == "today" {
dateFilter = time.Now().Format("2006-01-02")
}
if match.Date == dateFilter {
table.Append(ParseMatch(round, match))
} else {
table.SetHeader([]string{})
}
}
}
}
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.Render()
}
func ParseMatch(round Round, match Matches) []string {
var teamOneInfo,teamTwoInfo = "",""
for _, goal := range match.Goals1 {
teamOneInfo += goal.Name + " '" + strconv.Itoa(goal.Minute) + "\n"
}
for _, goal := range match.Goals2 {
teamTwoInfo += goal.Name + " '" + strconv.Itoa(goal.Minute) + "\n"
}
//for _, goal := range match.Goals2 {
// teamOneInfo += goal.Name + " '" + strconv.Itoa(goal.Minute) + "\n"
//}
return []string{
round.Name,
match.Date+"\n"+match.Time,
match.Group,
match.TeamOne.Name + "\n" + strconv.Itoa(match.Score1),
teamOneInfo,
match.TeamTwo.Name + "\n" + strconv.Itoa(match.Score2),
teamTwoInfo,
match.Stadium.Name,
}
}