Created
February 24, 2022 20:58
-
-
Save keerok/9cc7b6aaf58361e8a9de407ef51b8761 to your computer and use it in GitHub Desktop.
list dependents with stars
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
import requests | |
from time import sleep | |
import sys | |
names = [] | |
stars = [] | |
final = dict() | |
account_name = sys.argv[1] | |
project_name = sys.argv[2] | |
uri = "https://github.com/"+account_name+"/"+project_name+"/network/dependents?dependent_type=PACKAGE" | |
count = 0 | |
num = 0 | |
def executing(url): | |
r = requests.get(url,timeout=5) | |
allNames = r.text.split('data-hovercard-url') | |
allStars = r.text.split('octicon-star') | |
return allNames,allStars,r.text | |
def organize(names,stars,final,page): | |
num = 0 | |
for x in names: | |
if '.' in stars[num]: | |
final[float(stars[num])] = x | |
else: | |
final[int(stars[num])] = x | |
num+=1 | |
return final | |
def getNextUrls(text,page): | |
button = text.split('Next')[0] | |
new_uri = button.split('class="BtnGroup"')[1].split('href="')[1].split('"')[0].replace('&','&') | |
if page>0: | |
new_uri = button.split('class="BtnGroup"')[1].split('href="')[2].split('"')[0].replace('&','&') | |
return new_uri | |
def getUrls(listUrls): | |
n = [] | |
for i in listUrls: | |
if i.split('="')[1].split('" ')[0].replace("hovercard",'') != 'en' and not '/users' in i and not '/orgs' in i: | |
n.append(i.split('="')[1].split('" ')[0].replace("hovercard",'')) | |
return n | |
def getStars(listStars): | |
s = [] | |
for z in listStars: | |
if '<path fi' in z: | |
st = z.split('</path>')[1].split('</svg>')[1].split('</span>')[0].replace('\r','').strip() | |
if ',' in st: | |
st = st.replace(',','') | |
if st.isnumeric(): | |
s.append(st) | |
return s | |
while count < 5: | |
print('initiating') | |
allNames,allStars,text = executing(uri) | |
sleep(1) | |
listNames = getUrls(allNames) | |
listStars = getStars(allStars) | |
result = organize(listNames,listStars,dict(),count) | |
print("[PAGE "+str(count)+"]") | |
final.update(result) | |
uri = getNextUrls(text,count) | |
count+=1 | |
print(final) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment