Created
April 16, 2025 13:03
-
-
Save sspreitzer/9773332bc81bbd9e78f1578d2202804d to your computer and use it in GitHub Desktop.
To unfollow GitHub profiles that follow over 1'000 other profiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gh | |
import ( | |
"context" | |
"fmt" | |
"os" | |
"github.com/google/go-github/v71/github" | |
) | |
func UnfollowSpammers(followercount int) { | |
ctx := context.Background() | |
service := github.NewClient(nil).WithAuthToken(os.Getenv("GITHUB_TOKEN")).Users | |
if followercount == 0 { | |
followercount = 1000 | |
} | |
page := 1 | |
for { | |
followers, response, _ := service.ListFollowers(ctx, "", &github.ListOptions{Page: page}) | |
for _, v := range followers { | |
follower_user, _, _ := service.Get(ctx, v.GetLogin()) | |
if follower_user.GetFollowing() > followercount { | |
unf_resp, unf_err := service.Unfollow(ctx, follower_user.GetLogin()) | |
fmt.Println(unf_resp.StatusCode, unf_resp.Status) | |
if unf_resp.StatusCode != 204 { | |
fmt.Println("API Error HTTP Status", unf_resp.StatusCode, "with message:", unf_resp.Status) | |
} | |
if unf_err != nil { | |
fmt.Println("Could not remove user", v.GetLogin(), "error:", unf_err) | |
} | |
} | |
} | |
if response.NextPage == 0 { | |
break | |
} else { | |
page++ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment