From c4cf4dfbd6af95b08dddc1a84d94a0380ec57ca2 Mon Sep 17 00:00:00 2001 From: bel Date: Thu, 2 Apr 2020 23:23:53 +0000 Subject: [PATCH] working but should scroll emails --- config.go | 3 +++ main.go | 7 ------- upload.go | 19 +++++++++++-------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index 7a0c32f..749196e 100644 --- a/config.go +++ b/config.go @@ -16,6 +16,7 @@ type Config struct { TodoAddr string TodoToken string TodoList string + TodoTag string Storage storage.DB } @@ -31,6 +32,7 @@ func NewConfig() Config { as.Append(args.STRING, "todopass", "todo pass", "gJtEXbbLHLf54yS9EdujtVN2n6Y") as.Append(args.STRING, "todotoken", "todo token", "") as.Append(args.STRING, "todolist", "todo list", "") + as.Append(args.STRING, "todotag", "todo tag", "expense") as.Append(args.STRING, "authaddr", "auth addr", "https://auth.remote.blapointe.com") as.Append(args.STRING, "store", "store type", "map") @@ -100,6 +102,7 @@ func NewConfig() Config { TodoAddr: as.GetString("todoaddr"), TodoToken: token, TodoList: list, + TodoTag: as.GetString("todotag"), Storage: storage, } return config diff --git a/main.go b/main.go index ce24754..860b85b 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "local/sandbox/contact/contact" "log" - "time" ) func main() { @@ -13,12 +12,6 @@ func main() { From: config.EmailUser, Password: config.EmailPass, } - log.Println(emailer) - - //{45b6895c6dd6345f46e6e15dd2c61f03 Chase 12.86 GOOGLE *GSUITE_blapo [Wed, 1 Apr 2020 10:14:11 -0400 (EDT)]} - log.Println(Upload(config, NewTransaction("11.11", "vendor", time.Now().String(), Bank(0)))) - - return emails, err := emailer.Read() if err != nil { panic(err) diff --git a/upload.go b/upload.go index f3475fa..adecde5 100644 --- a/upload.go +++ b/upload.go @@ -1,20 +1,19 @@ package main import ( - "errors" + "fmt" + "io/ioutil" "local/oauth2" - "log" "net/http" "net/url" "strings" - "time" ) func Upload(config Config, transaction *Transaction) error { params := url.Values{ - "list": {"2548023766"}, - "title": {"test task: " + time.Now().String()}, - "tag": {"expense"}, + "list": {config.TodoList}, + "title": {fmt.Sprintf("%v: %s @ %s @ %s", transaction.Bank, transaction.Amount, transaction.Account, transaction.Date)}, + "tag": {config.TodoTag}, } req, err := http.NewRequest("POST", config.TodoAddr+"/ajax.php?newTask", strings.NewReader(params.Encode())) if err != nil { @@ -26,6 +25,10 @@ func Upload(config Config, transaction *Transaction) error { if err != nil { return err } - log.Printf("%+v\n\n%+v", req, resp) - return errors.New("not impl") + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + b, _ := ioutil.ReadAll(resp.Body) + return fmt.Errorf("bad status from todo: %v: %s", resp.StatusCode, b) + } + return nil }