-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
unfollowing_my_unfollowers.py
109 lines (98 loc) · 4.01 KB
/
unfollowing_my_unfollowers.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
#!/usr/bin/env python
# coding:utf-8
# | |
# --+----------------------------------------------------------+--
# | Code by : yasserbdj96 |
# | Email : [email protected] |
# | Github : https://github.com/yasserbdj96 |
# | BTC : bc1q2dks8w8uurca5xmfwv4jwl7upehyjjakr3xga9 |
# --+----------------------------------------------------------+--
# | all posts #yasserbdj96 ,all views my own. |
# --+----------------------------------------------------------+--
# | |
#START{
# IMPORT
import requests
import argparse
from base64 import b64encode
import time
import shutil
from hexor import *
import os
from datetime import datetime
# INPUT ARG
ap = argparse.ArgumentParser()
ap.add_argument('-t', '--token', required=True)
ap.add_argument('-m', '--username', required=True)
args = ap.parse_args()
p1=hexor(False,"hex")
# RESPONE AUTH
HEADERS = {"Authorization": "Basic " + b64encode(str(args.username + ":" + args.token).encode('utf-8')).decode('utf-8')}
res = requests.get("https://api.github.com/user", headers=HEADERS)
if(res.status_code != 200):
p1.c("Failure to Authenticate! Please check PersonalAccessToken and Username!","#ff0000")
exit(1)
else:
p1.c("Authentication Succeeded!","#22a701")
# SESSION HEADER
sesh = requests.session()
sesh.headers.update(HEADERS)
# OUTPUT list of my followers:
def followers(args):
target = args.username
res = sesh.get("https://api.github.com/users/" + target + "/followers")
linkArray = requests.utils.parse_header_links(res.headers['Link'].rstrip('>').replace('>,<', ',<'))
url = linkArray[1]['url']
lastPage = url.split('=')[-1]
followers = []
print('Grabbing '+target+' Followers\nThis may take a while... there are '+str(lastPage)+' pages to go through.')
x=0
for i in range(1,int(lastPage)+1):
res = sesh.get('https://api.github.com/users/' + target + "/followers?page=" + str(i)).json()
for user in res:
followers.append(user['login'])
#make_README(user['login'],user['avatar_url'])
print("Total Followers: "+str(len(followers)))
return followers
# OUTPUT list of i'm following:
def following(args):
target = args.username
res = sesh.get("https://api.github.com/users/" + target + "/following")
linkArray = requests.utils.parse_header_links(res.headers['Link'].rstrip('>').replace('>,<', ',<'))
url = linkArray[1]['url']
lastPage = url.split('=')[-1]
following = []
print('Grabbing '+target+' Following\nThis may take a while... there are '+str(lastPage)+' pages to go through.')
x=0
for i in range(1,int(lastPage)+1):
res = sesh.get('https://api.github.com/users/' + target + "/following?page=" + str(i)).json()
for user in res:
following.append(user['login'])
print("Total Following: "+str(len(following)))
return following
def whitelist():
whitelist_users = []
try:
with open("whitelist.txt") as file_in:
for line in file_in:
whitelist_users.append(line.replace('\n',''))
except:
pass
return whitelist_users
def unfollowing_my_unfollowers(followers_list,following_list):
whitelist_users=whitelist()
print("Starting to Unfollowing Users...")
for i in range(len(following_list)):
if not following_list[i] in followers_list and not following_list[i] in whitelist_users:
time.sleep(2)
res = sesh.delete('https://api.github.com/user/following/' + following_list[i])
if res.status_code != 204:
print("Rate-limited, please wait until it finish!")
time.sleep(60)
else:
print("Unfollowing : "+ following_list[i])
followers_list=followers(args)
following_list=following(args)
unfollowing_my_unfollowers(followers_list,following_list)
#print(followers_list)
#print(following_list)