This commit is contained in:
Erik Winter 2024-08-16 08:56:50 +01:00
parent 4699109e81
commit d65ee1eb65
3 changed files with 85 additions and 2 deletions

View File

@ -1,7 +1,8 @@
package main
import "fmt"
import "os"
func main() {
fmt.Println("hoi")
td := NewTodoist(os.Getenv("TODOIS_API_TOKEN"))
td.Run()
}

48
task/task.go Normal file
View File

@ -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
}

34
todoist.go Normal file
View File

@ -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")
}
}
}