forked from fedir/yrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.go
58 lines (51 loc) · 1.17 KB
/
view.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
package main
import (
"fmt"
"os"
"strconv"
"github.com/fedir/yrank/youtube"
"github.com/olekukonko/tablewriter"
)
func print(vs []youtube.VideoStatistics, of string) {
table := tablewriter.NewWriter(os.Stdout)
if of == "table" {
table.SetRowLine(true)
table.SetCenterSeparator("+")
table.SetColumnSeparator("|")
table.SetRowSeparator("-")
table.SetAlignment(tablewriter.ALIGN_CENTER)
} else if of == "markdown" {
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.SetAutoWrapText(false)
}
table.SetHeader([]string{
"Title",
"URL",
"Likes",
"Positive interestingness",
"Total reaction",
"Global buzz",
"Views",
"Dislikes",
"Comments",
})
for _, vsi := range vs {
if vsi.Title != "" {
table.Append(
[]string{
vsi.Title,
vsi.URL,
strconv.Itoa(vsi.LikeCount),
fmt.Sprintf("%.4f", vsi.PositiveInterestingness),
fmt.Sprintf("%.4f", vsi.TotalReaction),
strconv.Itoa(vsi.GlobalBuzz),
strconv.Itoa(vsi.ViewCount),
strconv.Itoa(vsi.DislikeCount),
strconv.Itoa(vsi.CommentCount),
},
)
}
}
table.Render() // Send output
}