-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
37 lines (31 loc) · 898 Bytes
/
main.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
package main
import (
log "github.com/sirupsen/logrus"
"os"
"github.com/nicovillanueva/timew-to-sheets/gsheets"
"github.com/nicovillanueva/timew-to-sheets/hashing"
"github.com/nicovillanueva/timew-to-sheets/timew"
)
const (
sheetIDEnvVar = "TW_SPREADSHEET_ID"
)
func init() {
log.SetLevel(log.InfoLevel)
}
func main() {
spreadsheetID := os.Getenv(sheetIDEnvVar)
if spreadsheetID == "" {
log.Fatal("spreadsheet ID not provided; set it via an environment variable named ", sheetIDEnvVar)
}
_, summary := timew.ParseTimeWarrior(os.Stdin)
rp := gsheets.RequestPool{}
for month, entries := range summary.SplitIntoMonths() {
rp.AddMany(gsheets.NewStyledSheetRequests(month))
rp.AddOne(entries.Request(hashing.HashDate(month)))
}
err := gsheets.DoBatchUpdate(spreadsheetID, rp)
if err != nil {
log.Fatalf("error performing batch update: %v", err)
}
log.Infof("all done")
}