Skip to content

Instantly share code, notes, and snippets.

@mananpal1997
Last active October 3, 2017 19:28
Show Gist options
  • Save mananpal1997/eda4b546d092265af22c66ec229aa6e1 to your computer and use it in GitHub Desktop.
Save mananpal1997/eda4b546d092265af22c66ec229aa6e1 to your computer and use it in GitHub Desktop.
"""
Take a github username in input, find who he/she follows, and then stalk his/her followers.
"""
import requests
from bs4 import *
def get_info(names, recent_activity):
for name in names.keys():
res = requests.get('https://github.com/' + name + '?tab=repositories')
soup = BeautifulSoup(res.text,'html.parser')
names.setdefault(name, [])
for repository in soup.findAll('a'):
if(('/'+name+'/') in str(repository)):
if(repository.text != None):
repository_name = repository.text.strip()
try:
junk = int(repository_name.replace(",", ""))
continue
except:
pass
names[name].append("Repo name : "+repository_name)
for name in names.keys():
res = requests.get('https://github.com/' + name + '?tab=repositories')
soup = BeautifulSoup(res.text,'html.parser')
names.setdefault(name, [])
index = 0
for x in soup.findAll('div',{'class':'repo-list-stats'}):
l = False
z = ""
for y in x.children:
if('programmingLanguage' in str(y)):
l = True
z = y.text.strip()
break
if(l==True):
names[name][index] += ("\n\t\tTechnology/Langauge(s) used : "+z+"\n")
else:
names[name][index] += ("\n\t\tNo Technology/Language used.\n")
index += 1
for name in recent_activity.keys():
res = requests.get('https://github.com/' + name)
soup = BeautifulSoup(res.text,'html.parser')
full_name = soup.find('span',{'class':'vcard-fullname'}).text
print("HANDLE : %s, NAME : %s" % (name, full_name))
recent_activity.setdefault(name, [])
try:
activity = soup.find('ul',{'class':'simple-conversation-list'})
act_list = activity.findAll('li')
for acts in act_list:
cont = acts.contents
commit = cont[1].text.strip() + ' on ' + cont[2].strip()
recent_activity[name].append(commit)
except:
recent_activity[name].append("No recent commits !")
print("\nRetreiving data : \n")
for name in names.keys():
print(name)
print('\tRepos : ')
rep_list = names[name]
for rep in rep_list:
print('\t\t')
print(rep)
print('\tRecent commits : ')
commit_list = recent_activity[name]
for commit in commit_list:
print('\t\t')
print(commit)
print()
if(__name__ == '__main__'):
x = raw_input("Type github handle : ")
response = requests.get('https://github.com/' + x + '/following')
soup = BeautifulSoup(response.text,'html.parser')
list_tag = soup.find('ol',{'class':'follow-list clearfix'})
devs = list_tag.findAll('li') # developers which user follows
names = {}
recent_activity = {}
print("People you follow : \n")
for dev in devs:
y = str(dev.find('a'))
end = y.find('>')
start = y.find('"',8,end) # string manipulation on variable y
names.update({y[start+2:end-1]:[]})
recent_activity.update({y[start+2:end-1]:[]})
get_info(names,recent_activity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment