/
main.py
50 lines (45 loc) · 1.92 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
j = 1
i = 1
print("Welcome to GithubFollower V.0.1")
print("To Start Following Create a Github access-token")
username = input("Type Your Own Username : ")
access_token = input("Type Your Own Fine-Grained Personal Access Token : ")
user_to_follow_followers = input("Type id of User to Follow : ")
def follow():
global i
global j
global username
global user_to_follow_followers
headers = {
"Authorization": f"token " + access_token,
"Accept": "application/vnd.github.v3+json"
}
response = requests.get(
f"https://api.github.com/users/" + user_to_follow_followers + "/followers?per_page=100&page=" + str(j),
headers=headers)
if response.status_code == 200:
followers = response.json()
for follower in followers:
z = str(i + (j - 1) * 100) + "."
response = requests.get(f"https://api.github.com/user/following/" + follower['login'] + "", headers=headers)
if response.status_code == 204:
print(z + f"You are already following " + follower['login'] + "!")
elif response.status_code == 404:
response = requests.put(f"https://api.github.com/user/following/" + follower['login'] + "",
headers=headers)
if response.status_code == 204:
print(z + f"You are now following " + follower['login'] + "!")
else:
print(z + f"Failed to follow " + follower['login'] + ".")
else:
print(z + f"Failed to check if you are following " + follower['login'] + ".")
i += 1
if i == 101:
i -= 100
j += 1
follow()
else:
print(f"Failed to retrieve followers for " + user_to_follow_followers + ".")
follow()
print('Following Ended Successfully !')