func main() { viper.AutomaticEnv() groupID = viper.GetInt("id") token = viper.GetString("token") fmt.Println(groupID, token) api := vk.NewWithToken(token) start := time.Now() getAllUsers(api) end := time.Now() fmt.Println("users loaded", end.Sub(start)) }
func main() { flag.Parse() api := vk.NewWithToken(token) groups, err := api.Groups.GetForUser(userID) if err != nil { fmt.Println("error:", err) os.Exit(2) } for _, group := range groups { fmt.Printf("%+v\n", group) } }
func main() { viper.AutomaticEnv() groupID = viper.GetInt("id") token = viper.GetString("token") fmt.Println(groupID, token) api := vk.NewWithToken(token) cfg := vcg.Config{ MongoURL: "localhost", Database: "vk-common-groups", } a, err := vcg.New(cfg) if err != nil { log.Fatal(err) } groups, err := a.Groups.All() if err != nil { log.Fatal(err) } var totalUsers = 0 for _, group := range groups { totalUsers += group.MembersCount } fmt.Println("groups:", len(groups), "users:", totalUsers) for id, group := range groups { log.Println(id, "/", len(groups), group.ID, group.Title, group.MembersCount) start := time.Now() groupID = group.ID collected := a.Users.Collected(groupID) log.Println("collected:", collected) if alreadyCollected(collected, group) { fmt.Println("already collected") continue } if err := getAllUsers(api, a); err != nil { fmt.Println("fatal:", err) } if err := a.Users.RemoveOld(groupID, start); err != nil { fmt.Println("remove fatal:", err) } end := time.Now() duration := end.Sub(start) fmt.Println("users loaded", duration) time.Sleep(time.Second) } }
func main() { token = viper.GetString("token") userID = viper.GetInt("id") api := vk.NewWithToken(token) cfg := vcg.Config{ MongoURL: viper.GetString("mongo"), Database: viper.GetString("db"), } a, err := vcg.New(cfg) if err != nil { log.Fatal(err) } groups, err := api.Groups.GetForUser(userID) if err != nil { fmt.Println("error:", err) os.Exit(2) } if err := a.Groups.UpdateFromVK(groups); err != nil { fmt.Println("error:", err) os.Exit(3) } fmt.Println("ok", len(groups)) }