Skip to content

Instantly share code, notes, and snippets.

@hctilg
Created August 27, 2024 08:04
Show Gist options
  • Save hctilg/03488abc526fece3e4cf509438af6f90 to your computer and use it in GitHub Desktop.
Save hctilg/03488abc526fece3e4cf509438af6f90 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
from requests import get
class github():
def __init__(self, user):
self.user = user
def following(self):
return self.get_users("following")
def followers(self):
return self.get_users("followers")
def get_users(self, type = "following" or "followers"):
users, i = [], 0
len_chunk_users = 1
while (len_chunk_users > 0):
i += 1
soup = BeautifulSoup(get(f"https://github.com/{self.user}?page={i}&tab={type}").text, 'html.parser')
container = soup.find(id="user-profile-frame")
elements = container.find_all(class_ = "d-table table-fixed col-12 width-full py-4 border-bottom color-border-muted")
len_elements = 0
for element in elements:
try:
len_elements += 1
users.append({
"username": element.find(class_ = "Link--secondary").text,
"profile": element.find(class_ = "avatar")["src"],
"name": element.find(class_ = "f4 Link--primary").text
})
except Exception as error:
print("Error:", error)
continue
len_chunk_users = len_elements
return users
gh = github(input("username: "))
following = gh.following()
print(" Following: ", len(following))
followers = gh.followers()
print(" Followers: ", len(followers))
print('-' * 20)
i = 0
for user in following:
i += 1
if (user["username"] in [follower["username"] for follower in followers]): continue
print(f" [{str(i).ljust(2, '0')}] {user['name']} - {user['username']}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment