/
work4_10.go
48 lines (41 loc) · 1.37 KB
/
work4_10.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 (
"fmt"
"log"
"os"
"time"
"github.com/caistrong/gopl-homework/src/chapter4/work4_10/github"
)
// run command
// go run ./src/chapter4/work4_10/work4_10.go 知识图谱 简单智能问答
func main() {
result, err := github.SearchIssues(os.Args[1:])
if err != nil {
log.Fatal(err)
}
fmt.Printf("total count %d issues: \n", result.TotalCount)
now := time.Now()
aMonthAgo := now.AddDate(0, -1, 0)
aYearAgo := now.AddDate(-1, 0, 0)
lessMonthIssues := []*github.Issue{}
lessYearMoreThanMonthIssues := []*github.Issue{}
moreThanYearIssues := []*github.Issue{}
for _, item := range result.Items {
if item.CreatedAt.After(aMonthAgo) {
lessMonthIssues = append(lessMonthIssues, item)
} else if item.CreatedAt.After(aYearAgo) {
lessYearMoreThanMonthIssues = append(lessYearMoreThanMonthIssues, item)
} else {
moreThanYearIssues = append(moreThanYearIssues, item)
}
}
for _, issue := range lessMonthIssues {
fmt.Printf("最近一月:\t%s\t%s\t%s\t%s\n", issue.Title, issue.HTMLURL, issue.CreatedAt, issue.User.Login)
}
for _, issue := range lessYearMoreThanMonthIssues {
fmt.Printf("最近一年:\t%s\t%s\t%s\t%s\n", issue.Title, issue.HTMLURL, issue.CreatedAt, issue.User.Login)
}
for _, issue := range moreThanYearIssues {
fmt.Printf("一年以前:\t%s\t%s\t%s\t%s\n", issue.Title, issue.HTMLURL, issue.CreatedAt, issue.User.Login)
}
}