-
Notifications
You must be signed in to change notification settings - Fork 2
/
raptors.go
37 lines (29 loc) · 1023 Bytes
/
raptors.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"os"
"time"
"github.com/bilogub/raptors/pkg/renderer"
"github.com/bilogub/raptors/pkg/response"
)
func main() {
showPreviousGames := flag.Bool("prev", false, "Show previous 5 games")
teamSlug := flag.String("team", "raptors", "Pick your team. Default is raptors")
recordsNumToShow := flag.Int("num", 5, "How many records to show. Default is 5")
flag.Parse()
year := 2019 // time.Now().Year() still available on 2019 url only
url := fmt.Sprintf("http://data.nba.net/json/cms/%d/team/%s/schedule.json", year, *teamSlug)
req, _ := http.NewRequest("GET", url, nil)
res, error := http.DefaultClient.Do(req)
if error != nil {
fmt.Fprintf(os.Stderr, "Error occurred while connecting to API. Please try again later: %v\n", error)
os.Exit(1)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
output := response.Processor{}.Call(body, *showPreviousGames, *recordsNumToShow)
renderer.Renderer{}.Call(renderer.Terminal{}, output)
}