Exemple #1
0
func getAllUsers(api *vk.Client) (err error) {
	var (
		gotUsers int
		n        int
		users    []vk.User
	)
	fields := vk.GroupGetFields{
		Fields:  vk.UserFields,
		Offset:  0,
		GroupID: groupID,
	}
	for {
		fields.Offset = gotUsers
		users, n, err = api.Groups.GetBatch(fields)
		if err != nil {
			return err
		}
		gotUsers += len(users)
		fmt.Println("got", gotUsers, "of", n)
		if gotUsers >= n {
			// got all users
			fmt.Println("got all", gotUsers)
			return nil
		}
	}
}
Exemple #2
0
func getAllUsers(api *vk.Client, a *vcg.Application) (err error) {
	var (
		gotUsers int
		n        int
		users    []vk.User
	)
	fields := vk.GroupGetFields{
		Fields:  vk.UserFields,
		Offset:  0,
		GroupID: groupID,
	}
	start := time.Now()

	for {
		fields.Offset = gotUsers
		users, n, err = api.Groups.GetBatch(fields)
		if err != nil {
			return err
		}
		if err := a.Users.UpdateFromVK(groupID, users); err != nil {
			return err
		}
		gotUsers += len(users)
		fmt.Println("got", gotUsers, "of", n)
		if gotUsers >= n {
			// got all users
			end := time.Now()
			duration := end.Sub(start)
			speed := float64(gotUsers) / duration.Seconds()
			fmt.Println("got all", gotUsers, "speed", speed, "per second")
			return nil
		}
	}
}