├── README.md └── main.go /README.md: -------------------------------------------------------------------------------- 1 | # ght 2 | 3 | GitHub Trend in CUI 4 | 5 | ![](http://go-gyazo.appspot.com/9d0da8f23080b77a.png) 6 | 7 | ## Usage 8 | 9 | ``` 10 | $ ght [language] 11 | ``` 12 | 13 | ## Installation 14 | 15 | ``` 16 | $ go get github.com/mattn/ght 17 | ``` 18 | 19 | ## License 20 | 21 | MIT 22 | 23 | ## Author 24 | 25 | Yasuhiro Matsumoto (a.k.a mattn) 26 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | 8 | "github.com/PuerkitoBio/goquery" 9 | "github.com/daviddengcn/go-colortext" 10 | "github.com/mattn/go-runewidth" 11 | ) 12 | 13 | func main() { 14 | lang := "" 15 | switch len(os.Args) { 16 | case 1: 17 | case 2: 18 | lang = os.Args[1] 19 | default: 20 | fmt.Fprintf(os.Stderr, "usage of %s: [language]", os.Args[0]) 21 | os.Exit(1) 22 | } 23 | uri := "https://github.com/trending" 24 | if lang != "" { 25 | uri += "?l=" + lang 26 | } 27 | doc, err := goquery.NewDocument(uri) 28 | if err != nil { 29 | fmt.Printf("%s: %s\n", os.Args[0], err) 30 | os.Exit(1) 31 | } 32 | 33 | doc.Find("article").Each(func(_ int, s *goquery.Selection) { 34 | if href, ok := s.Find("h1 a").First().Attr("href"); ok { 35 | if strings.HasPrefix(href, "/") { 36 | href = "https://github.com" + href 37 | } 38 | desc := strings.TrimSpace(s.Find("p").First().Text()) 39 | desc = runewidth.Wrap(desc, 76) 40 | desc = " " + strings.Replace(desc, "\n", "\n ", -1) 41 | 42 | ct.ChangeColor(ct.Yellow, false, ct.None, false) 43 | fmt.Println(href) 44 | ct.ChangeColor(ct.Green, false, ct.None, false) 45 | fmt.Println(desc) 46 | ct.ResetColor() 47 | } 48 | }) 49 | } 50 | --------------------------------------------------------------------------------