package main import "surdeus.su/core/amo" import "surdeus.su/core/amo/api" import "surdeus.su/core/cli/mtool" import "surdeus.su/core/amo/companies" import "encoding/json" import "log" import "os" const MEPR = api.MaxEntitiesPerRequest var updateComs = mtool.T("update-companies").Func(func(flags *mtool.Flags){ var ( opts DefaultFlags ) MakeDefaultFlags(&opts, flags) flags.Parse() client, err := amo.NewClient(opts.SecretPath) if err != nil { log.Fatalf("NewAmoClient(...): %s\n", err) } cs := []companies.Company{} dec := json.NewDecoder(os.Stdin) err = dec.Decode(&cs) if err != nil { log.Fatalf("json.Decode(...): %s\n", err) } n := len(cs)/MEPR + 1 for i:=0 ; i= len(cs) { end = len(cs) } if len(cs) == 0 { continue } slice := cs[start:end] if opts.Verbose { log.Printf("Updating %d companies...\n", len(slice)) } err = client.UpdateCompanies(slice) if err != nil { log.Fatalf( "client.UpdateCompanies(...) len(...) =%d: %s\n", len(slice), err, ) } } })