-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
165 lines (153 loc) · 4.99 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#==========================================#
# Developed by : github.com/rohit-chouhan, github.com/7k5x
# License : MIT
# Last Update : August 14, 2021
#==========================================#
import requests
#Using GetPass, so you should have Python 2.5 or higher
import getpass
#KeyboardInterrupt in loop means Ctrl+C
def follow(t):
page = 1
indexing = 0
try:
limit=int(input("\n Enter Follow Limit: "))
except ValueError:
limit=1000000
except:
exit(1)
try:
user=str(input(" Enter The User name of Person to Follow their Followers: "))
except:
print("Please enter your username")
exit(1)
for i in range(limit):
try:
response = requests.get('https://api.github.com/users/'+user+'/followers?page='+str(page), headers= {'Authorization' : 'Bearer '+t+''})
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print("Error getting response")
try:
res = response.json()
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print("Error parsing JSON")
try:
requests.put('https://api.github.com/user/following/'+res[indexing]['login'], headers= {'Authorization' : 'Bearer '+t+''})
print(" ("+str(i+1)+") Followed User Successfully: @"+res[indexing]['login'])
#IndexError is caused when your limit is over the number of followers the user has, so it's not an error to worry about
except IndexError:
break
except KeyboardInterrupt:
print('\n')
exit(0)
except:
try:
print("Error following user @"+res[indexing]['login'])
except:
print("Error following user "+str(i+1))
#There are 30 people(0~29) per API page index. This might change later on.
if indexing==29:
page+=1
indexing=0
elif i==limit:
break
else:
pass
indexing+=1
print("\n\n===== Task Completed =====")
print("\n\nNote: Github takes 5-10min to update!")
def unfollow(u,t):
page = 1
indexing = 0
try:
limit=int(input("\n Enter UnFollow Limit: "))
except ValueError:
#10M is more than enough
limit=1000000
except:
exit(1)
for i in range(limit):
try:
response = requests.get('https://api.github.com/users/'+u+'/following?page='+str(page), headers= {'Authorization' : 'Bearer '+t+''})
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print("Error getting response")
try:
res = response.json()
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print("Error parsing JSON")
try:
requests.delete('https://api.github.com/user/following/'+res[indexing]['login'], headers= {'Authorization' : 'Bearer '+t+''})
print(" ("+str(i+1)+") Unfollowed User Successfully: @"+res[indexing]['login'])
#IndexError is caused when your limit is over the number of followers the user has, so it's not an error to worry about
except KeyboardInterrupt:
print('\n')
exit(0)
except IndexError:
break
except:
try:
print("Error unfollowing user @"+res[indexing]['login'])
except:
print("Error unfollowing user "+str(i+1))
#There are 30 people(0~29) per API page index. This might change later on.
if indexing==29:
page+=1
indexing=0
elif i==limit:
break
else:
pass
indexing+=1
print("\n\n===== Task Completed =====")
print("\n\nNote: Github takes some time to update!")
print("============Github Tool by @rohit-chouhan =============")
try:
username=input("Your Username: ")
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print('Error in input')
exit(1)
#Use getpass for token security
try:
usertoken=getpass.getpass('Token: ')
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print('Error in input')
#GetPass doesn't show your stuff, so you could enter the wrong thing. This solves the problem.
if not usertoken.startswith("ghp_"):
print('You didn\'t input a proper access token. It should start with ghp_ and should be 40 letters in length.')
exit(1)
if len(usertoken)>40 or len(usertoken)<40:
print('You didn\'t input a proper access token. It should start with ghp_ and should be 40 letters in length.')
exit(1)
print("\n\n========= Tools ===========")
print("1.Follow\n2.Unfollow")
try:
ans = input("\nYour Choice: ")
except KeyboardInterrupt:
print('\n')
exit(0)
except:
print('Error in input')
if ans=="1":
follow(usertoken)
elif ans=="2":
unfollow(username,usertoken)
else:
print("Wrong input")
exit(1)