-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (39 loc) · 915 Bytes
/
main.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
package main
import (
"bytes"
"cric/model"
"cric/utils"
"encoding/json"
"fmt"
"os"
xj "github.com/basgys/goxml2json"
"github.com/ttacon/chalk"
)
const LIVE_SCORES = "http://static.espncricinfo.com/rss/livescores.xml"
func main() {
xmlBytes, _ := utils.GetXML(LIVE_SCORES)
data := bytes.NewReader(xmlBytes)
js, err := xj.Convert(data)
if err != nil {
fmt.Println("Coudn't fetch the Live scores.")
utils.ExitGracefully(err)
}
page := &model.Page{}
err = json.Unmarshal(js.Bytes(), page)
if err != nil {
fmt.Println("Couldn't fetch the Live scores.")
}
items := &[]model.Item{}
*items = utils.GetAllItems(page)
if err != nil {
fmt.Println("Couldn't fetch the Live scores.")
} else {
if len(os.Args) < 2 {
fmt.Printf(chalk.Green.Color("🟩 Currently live: \n\n\n"))
utils.PrintLiveMatches(*items)
} else {
team := os.Args[1]
utils.GetScore(team, *items)
}
}
}