-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 893 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
49
50
51
52
53
54
package main
import (
"net/http"
"os"
"github.com/cbguder/revzilla/zilla"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
)
func main() {
if len(os.Args) < 2 {
return
}
err := fetch(os.Args[1])
if err != nil {
panic(err)
}
}
func fetch(url string) error {
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()
p := zilla.NewParser(resp.Body)
res, err := p.Parse()
if err != nil {
return err
}
t := table.NewWriter()
t.Style().Format.Header = text.FormatDefault
t.SetTitle(res.Products[0].Name)
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Color / Size", "MSRP", "Retail", "Members", "In Stock?"})
for _, sku := range res.SkuDetails {
t.AppendRow(table.Row{
sku.OptionsDescription,
sku.Msrp,
sku.Retail,
sku.LoyaltyPrice,
sku.InStock,
})
}
t.Render()
return nil
}