|
|
|
@ -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])
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
} |