diff --git a/main.go b/main.go index f7a5b8e..6b4c6c1 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,8 @@ package main -import "fmt" +import "os" func main() { - fmt.Println("hoi") + td := NewTodoist(os.Getenv("TODOIS_API_TOKEN")) + td.Run() } diff --git a/task/task.go b/task/task.go new file mode 100644 index 0000000..79f2ff0 --- /dev/null +++ b/task/task.go @@ -0,0 +1,48 @@ +package task + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "os" + "time" +) + +type Recurring struct { + Days int `json:"days"` + Start time.Time `json:"start"` + Name string `json:"name"` + Project string `json:"project"` +} + +type Period struct { + Start time.Time `json:"start"` + End time.Time `json:"end"` + Name string `json:"name"` + Project string `json:"project"` +} + +type All struct { + Recurrings []Recurring `json:"recurrings"` + Periods []Period `json:"periods"` +} + +func LoadAll(path string) (All, error) { + file, err := os.Open(path) + if err != nil { + return All{}, fmt.Errorf("could not open file: %w", err) + } + + defer file.Close() + data, err := ioutil.ReadAll(file) + if err != nil { + return All{}, fmt.Errorf("could not read file: %w", err) + } + + all := All{} + if err := json.Unmarshal(data, &all); err != nil { + return All{}, fmt.Errorf("could not parse file: %w", err) + } + + return all, nil +} diff --git a/todoist.go b/todoist.go new file mode 100644 index 0000000..2278773 --- /dev/null +++ b/todoist.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "net/http" + "time" +) + +type Todoist struct { + apiKey string + client http.Client + done chan bool +} + +func NewTodoist(apiKey string) *Todoist { + td := &Todoist{ + apiKey: apiKey, + done: make(chan bool), + } + + return td +} + +func (td *Todoist) Run() { + ticker := time.NewTicker(time.Second) + for { + select { + case <-td.done: + return + case <-ticker.C: + fmt.Println("hoi") + } + } +}