-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.2 KB
/
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
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
package main
import (
"fmt"
"os"
"todoist-to-org-mode/orgmode"
"todoist-to-org-mode/todoist"
"github.com/spf13/pflag"
)
func main() {
var apiKeys []string
pflag.StringArrayVarP(&apiKeys, "key", "k", nil, "ApiKeys to be used")
var destination string
pflag.StringVarP(&destination, "output", "o", "", "Name of file for saving results")
pflag.Parse()
var projects []todoist.Project
var tasks []todoist.Task
for _, key := range apiKeys {
client := todoist.Client{
ApiKey: key,
}
currentProjects, err := client.GetProjects()
if err != nil {
panic(err)
}
projects = append(projects, currentProjects...)
currentTasks, err := client.GetTasks()
if err != nil {
panic(err)
}
tasks = append(tasks, currentTasks...)
}
taskCreator := orgmode.TaskCreator{}
for _, v := range projects {
taskCreator.Add(v)
}
for _, v := range tasks {
taskCreator.Add(v)
}
orgmodeTasks, err := taskCreator.CreateOrgmodeTasks()
if err != nil {
panic(err)
}
buf, err := orgmode.TasksToBuffer(orgmodeTasks)
if err != nil {
panic(err)
}
if destination != "" {
if err = os.WriteFile(destination, buf.Bytes(), 0666); err != nil {
panic(err)
}
} else {
fmt.Print(buf.String())
}
}