-
Notifications
You must be signed in to change notification settings - Fork 0
/
R.go
135 lines (108 loc) · 3.74 KB
/
R.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"log"
"time"
"github.com/VojtechVitek/go-trello"
"github.com/faaaar/R/util"
"github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday"
)
var p = log.Println
var appKey = util.GetIniConfig("authorize", "appKey")
var token = util.GetIniConfig("authorize", "token")
var username = util.GetIniConfig("filter", "username")
var filterBoard = util.GetIniConfig("filter", "board")
var outputPath = util.GetIniConfig("path", "output")
func main() {
p("请求&&处理数据中...")
trelloClient, err := trello.NewAuthClient(appKey, &token)
util.CheckError(err)
markdownStr := ""
markdownStr += generateReportTitle()
markdownStr += generateCurrentWeekReport(trelloClient)
markdownStr += generateNextWeekReport(trelloClient)
markdownStr += "---\n"
markdownStr += "*此周报由 周报生成器 0.2 生成*\n"
markdownStr += "*开源地址: https://github.com/faaaar/R*\n"
p(markdownStr)
p("正在生成markdown到" + outputPath + "...")
util.WriteFile(outputPath+"/"+util.GetTodayDateString()+".md", markdownStr)
unsafe := blackfriday.Run([]byte(markdownStr))
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
util.WriteFile(outputPath+"/"+util.GetTodayDateString()+".html", string(html))
// p("正在发送邮件...")
// util.SendMail(outputPath+"/"+util.GetTodayDateString()+".md", "("+startTime+" - "+endTime+")")
p("完成...")
}
func generateReportTitle() string {
timeNow := time.Now()
startTs, endTs := util.GetWeekDateRange(timeNow)
startTime := util.GetDateStringWithFormat(startTs, "2006/01/02")
endTime := util.GetDateStringWithFormat(endTs, "2006/01/02")
return "## " + startTime + " - " + endTime + " 周报 \n\n"
}
// generateCurrentWeekReport 生成本周工作内容
func generateCurrentWeekReport(trelloClient *trello.Client) string {
startTs, endTs := util.GetWeekDateRange(time.Now())
return "### 本周工作内容 \n\n" + generateWeekReport(trelloClient, startTs, endTs)
}
// generateNextWeekReport 生成下周工作计划
func generateNextWeekReport(trelloClient *trello.Client) string {
startTs, endTs := util.GetWeekDateRange(time.Now().AddDate(0, 0, 7))
return "### 下周工作计划 \n\n" + generateWeekReport(trelloClient, startTs, endTs)
}
// generateWeekReport 生成startTs和endTs时间范围内的工作内容
func generateWeekReport(trello *trello.Client, startTs int64, endTs int64) string {
user, _ := trello.Member(username)
userid := user.Id
boards, _ := user.Boards()
markdownStr := ""
for _, board := range boards {
boardName := board.Name
if boardName != filterBoard {
continue
}
cards, _ := board.Cards()
for _, card := range cards {
isOwnCard := false
memberIDList := card.IdMembers
for _, id := range memberIDList {
if id == userid {
isOwnCard = true
break
}
}
if isOwnCard {
if card.Due != "" {
t, _ := time.Parse(time.RFC3339, card.Due)
ts := t.Unix()
if ts > startTs && ts <= endTs {
typeStr := ""
if len(card.Labels) > 0 {
typeStr += "| "
}
for _, label := range card.Labels {
typeStr += label.Name + " | "
}
markdownStr = markdownStr + "### " + card.Name + "(完成时间: " + util.GetDateStringWithFormat(ts, "2006/01/02") + ")" + "\n\n"
markdownStr += typeStr + "\n\n"
markdownStr += card.Desc + "\n\n"
lists, _ := card.Checklists()
for _, list := range lists {
markdownStr += "#### " + list.Name + "\n"
for _, item := range list.CheckItems {
if item.State == "complete" {
markdownStr += "- [x] " + item.Name + "\n"
} else if item.State == "incomplete" {
markdownStr += "- [ ] " + item.Name + "\n"
}
}
markdownStr += "\n"
}
}
}
}
}
}
return markdownStr
}