diff --git a/config.json b/config.json index 105ba90..a75d1d7 100644 --- a/config.json +++ b/config.json @@ -21,7 +21,7 @@ ] }, { - "schedule": "2 4 * */1 *", + "schedule": "2 4 1 */1 *", "values": [ "Versicherungen", "Konto", @@ -30,7 +30,7 @@ ] }, { - "schedule": "3 4 * Jan,Mar,May,Jul,Sep,Nov *", + "schedule": "3 4 1 Jan,Mar,May,Jul,Sep,Nov *", "values": [ "GIS", "Konto", diff --git a/go.mod b/go.mod index 9852dd8..9c0666a 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.144spokes.com/mawas/create-expense go 1.17 require ( + github.com/robfig/cron/v3 v3.0.0 golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f google.golang.org/api v0.56.0 ) @@ -12,7 +13,6 @@ require ( github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/googleapis/gax-go/v2 v2.1.0 // indirect - github.com/robfig/cron/v3 v3.0.0 // indirect go.opencensus.io v0.23.0 // indirect golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420 // indirect golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect diff --git a/main.go b/main.go index 9f2a2f9..51524a4 100644 --- a/main.go +++ b/main.go @@ -131,6 +131,8 @@ func main() { // Schedule crons c := cron.New() for _, job := range config.Jobs { + job := job + log.Printf("job %s %s;%s;%s;%.02f queued", job.Schedule, job.Values[0], job.Values[1], job.Values[2], job.Values[3]) if _, err := c.AddFunc(job.Schedule, func() { writeExpense(client, ctx, config.SpreadsheetID, config.Range, job.Values) }); err != nil { @@ -140,56 +142,6 @@ func main() { c.Start() for { time.Sleep(time.Second) + // fmt.Printf("%#v\n", c.Entries()) } - // ctx := context.Background() - // b, err := ioutil.ReadFile("credentials.json") - // if err != nil { - // log.Fatalf("Unable to read client secret file: %v", err) - // } - // // If modifying these scopes, delete your previously saved token.json. - // config, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/spreadsheets") - // if err != nil { - // log.Fatalf("Unable to parse client secret file to config: %v", err) - // } - // client := getClient(config) - - // srv, err := sheets.NewService(ctx, option.WithHTTPClient(client)) - // if err != nil { - // log.Fatalf("Unable to retrieve Sheets client: %v", err) - // } - // // Prints the names and majors of students in a sample spreadsheet: - // // https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit - // // spreadsheetId := "1TT4oJ7B_Lq4quyizxK2DxGR_qhYtaG4Mn40j2MNpB6E" - // spreadsheetId := "1JpPdBi0xHpbfxtm5h1V7kQKzH_WPiIGuID8nQygk5o8" - // readRange := "Expenses!A2:E" - // valueInputOption := "USER_ENTERED" - // insertDataOption := "INSERT_ROWS" - // rb := &sheets.ValueRange{ - // MajorDimension: "ROWS", - // } - // row := []interface{}{time.Now().Format("2006-01-02"), "Testrecord", "Konto", "Fixkosten", 80.23} - // rb.Values = append(rb.Values, row) - // resp, err := srv.Spreadsheets.Values.Append(spreadsheetId, readRange, rb). - // ValueInputOption(valueInputOption).InsertDataOption(insertDataOption).Context(ctx).Do() - // if err != nil { - // log.Fatal(err) - // } - - // // TODO: Change code below to process the `resp` object: - // fmt.Printf("%#v\n", resp) - - // resp1, err := srv.Spreadsheets.Values.Get(spreadsheetId, readRange).Do() - // if err != nil { - // log.Fatalf("Unable to retrieve data from sheet: %v", err) - // } - - // if len(resp1.Values) == 0 { - // fmt.Println("No data found.") - // } else { - // fmt.Println("Date, Description, Account, Category, Expense:") - // for _, row := range resp1.Values { - // // Print columns A and E, which correspond to indices 0 and 4. - // fmt.Printf("%s, %s, %s, %s, %s\n", row[0], row[1], row[2], row[3], row[4]) - // } - // } }