Skip to content

Instantly share code, notes, and snippets.

@shijithpk
Created October 30, 2025 18:30
Show Gist options
  • Select an option

  • Save shijithpk/9c6109255e2789ae8899e48c917564e9 to your computer and use it in GitHub Desktop.

Select an option

Save shijithpk/9c6109255e2789ae8899e48c917564e9 to your computer and use it in GitHub Desktop.
script to automatically follow and unfollow people on github
import time
from ghapi.all import GhApi
#import os
import math
#github_token = os.getenv('GITHUB_TOKEN')
api = GhApi(token='GITHUB_TOKEN')
current_user_object = api.users.get_authenticated()
user_followers_len = int(current_user_object['followers'])
user_following_len = int(current_user_object['following'])
user_followers_list_objects = []
user_following_list_objects = []
followers_no_of_100s = math.ceil(user_followers_len/100)
following_no_of_100s = math.ceil(user_following_len/100)
for i in range(0, followers_no_of_100s):
object_list = api.users.list_followers_for_authenticated_user(100,i)
user_followers_list_objects.extend(object_list)
time.sleep(6)
for i in range(0, following_no_of_100s):
object_list = api.users.list_followed_by_authenticated_user(100,i)
user_following_list_objects.extend(object_list)
time.sleep(6)
user_followers_list = [x['login'] for x in user_followers_list_objects]
user_following_list = [x['login'] for x in user_following_list_objects]
they_follow_but_i_dont_follow_back = [x for x in user_followers_list if x not in user_following_list]
for userx in they_follow_but_i_dont_follow_back:
api.users.follow(userx)
time.sleep(6)
i_follow_but_no_follow_back = [x for x in user_following_list if x not in user_followers_list]
for userx in i_follow_but_no_follow_back:
api.users.unfollow(userx)
time.sleep(6)
#print('done and done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment