Created
December 7, 2015 22:56
-
-
Save ota42y/f40dd18687d3bd5350d8 to your computer and use it in GitHub Desktop.
wl_report
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Usage: | |
# get https://github.com/robdimsdale/wl | |
go get -u github.com/robdimsdale/wl | |
# set up wunderlist setting for wl | |
go build report.go | |
wl tasks --completed true -j | ./report | |
2015-11-30 10 tasks completed | |
07:37:51 mail check | |
07:59:23 review PR | |
22:06:09 create blog entry | |
*/ | |
package main | |
import ( | |
"os" | |
"fmt" | |
"time" | |
"sort" | |
"encoding/json" | |
) | |
type Task struct { | |
Title string | |
CompletedAt time.Time `json:"completed_at"` | |
} | |
type Tasks []Task | |
func (p Tasks) Len() int { | |
return len(p) | |
} | |
func (p Tasks) Swap(i, j int) { | |
p[i], p[j] = p[j], p[i] | |
} | |
func (p Tasks) Less(i, j int) bool { | |
return p[i].CompletedAt.Before(p[j].CompletedAt) | |
} | |
var dateStr string = "2006-01-02" | |
func main() { | |
dec := json.NewDecoder(os.Stdin) | |
var tasks []Task | |
err := dec.Decode(&tasks) | |
if err != nil{ | |
fmt.Println(err) | |
return | |
} | |
dateTaskskMap := make(map[string]Tasks) | |
// create 1 week dates | |
for i := 6; 0 <= i; i-- { | |
timeStr := time.Now().Local().AddDate(0, 0, -1 * i).Format(dateStr) | |
dateTaskskMap[timeStr] = make([]Task, 0) | |
} | |
for _, task := range tasks { | |
timeStr := task.CompletedAt.Local().Format(dateStr) | |
_, ok := dateTaskskMap[timeStr] | |
if ok { | |
dateTaskskMap[timeStr] = append(dateTaskskMap[timeStr], task) | |
} | |
} | |
for i := 6; 0 <= i; i-- { | |
timeStr := time.Now().Local().AddDate(0, 0, -1 * i).Format(dateStr) | |
todayTasks := dateTaskskMap[timeStr] | |
if len(todayTasks) != 0 { | |
fmt.Printf("\n%s %d tasks completed\n", timeStr, len(todayTasks)) | |
sort.Sort(todayTasks) | |
for _, task := range todayTasks { | |
fmt.Println(task.CompletedAt.Local().Format("15:04:05"), task.Title) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment