Skip to content

Commit bfac3aa

Browse files
updates github followers using python and shows
1 parent ada03d5 commit bfac3aa

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

Show_Github_Followers.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import requests
2+
import sys
3+
import re
4+
5+
if __name__ == "__main__":
6+
assert(len(sys.argv) == 4)
7+
handle = sys.argv[1]
8+
token = sys.argv[2]
9+
readmePath = sys.argv[3]
10+
11+
headers = {
12+
"Accept": "application/vnd.github.v3+json",
13+
"Authorization": f"token {token}"
14+
}
15+
16+
followers = []
17+
18+
for i in range(1, 100000):
19+
page = requests.get(f"https://api.github.com/users/{handle}/followers?page={i}&per_page=100", headers = headers).json()
20+
if len(page) == 0:
21+
break
22+
for follower in page:
23+
info = requests.get(follower["url"], headers = headers).json()
24+
if info["following"] > 10000:
25+
continue
26+
followers.append((info["followers"], info["login"], info["id"], info["name"] if info["name"] else info["login"]))
27+
print(followers[-1])
28+
29+
followers.sort(reverse = True)
30+
31+
html = "<table>\n"
32+
33+
for i in range(min(len(followers), 21)):
34+
login = followers[i][1]
35+
id = followers[i][2]
36+
name = followers[i][3]
37+
if i % 7 == 0:
38+
if i != 0:
39+
html += " </tr>\n"
40+
html += " <tr>\n"
41+
html += f''' <td align="center">
42+
<a href="https://github.com/{login}">
43+
<img src="https://avatars2.githubusercontent.com/u/{id}" width="100px;" alt="{login}"/>
44+
</a>
45+
<br />
46+
<a href="https://github.com/{login}">{name}</a>
47+
</td>
48+
'''
49+
50+
html += " </tr>\n</table>"
51+
52+
with open(readmePath, "r") as readme:
53+
content = readme.read()
54+
55+
newContent = re.sub(r"(?<=<!\-\-START_SECTION:top\-followers\-\->)[\s\S]*(?=<!\-\-END_SECTION:top\-followers\-\->)", f"\n{html}\n", content)
56+
57+
with open(readmePath, "w") as readme:
58+
readme.write(newContent)

0 commit comments

Comments
 (0)