forked from donkeyshaun/Instagram-Unfollow-Unfollowers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
igbot_nonacc.py
79 lines (62 loc) · 2.21 KB
/
igbot_nonacc.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
import time
from keys_ig import *
from InstagramAPI import InstagramAPI
def getTotalFollowers(api, user_id):
"""
Returns the list of followers of the user.
It should be equivalent of calling api.getTotalFollowers from InstagramAPI
"""
followers = []
next_max_id = True
while next_max_id:
# first iteration hack
if next_max_id is True:
next_max_id = ''
_ = api.getUserFollowers(user_id, maxid=next_max_id)
followers.extend(api.LastJson.get('users', []))
next_max_id = api.LastJson.get('next_max_id', '')
return followers
def getTotalFollowings(api, user_id):
"""
Returns the list of followers of the user.
It should be equivalent of calling api.getTotalFollowers from InstagramAPI
"""
followers = []
next_max_id = True
while next_max_id:
# first iteration hack
if next_max_id is True:
next_max_id = ''
_ = api.getUserFollowings(user_id, maxid=next_max_id)
followers.extend(api.LastJson.get('users', []))
next_max_id = api.LastJson.get('next_max_id', '')
return followers
def nonFollowers(followers, followings):
nonFollowers = {}
dictFollowers = {}
for follower in followers:
dictFollowers[follower['username']] = follower['pk']
for followedUser in followings:
if followedUser['username'] not in dictFollowers:
nonFollowers[followedUser['username']] = followedUser['pk']
return nonFollowers
def unFollow(number : int):
api = InstagramAPI(USERNAME, PASS)
api.login()
user_id = api.username_id
followers = getTotalFollowers(api, user_id)
following = getTotalFollowings(api, user_id)
nonFollow = nonFollowers(followers, following)
totalNonFollowers = len(nonFollow)
print('Number of followers:', len(followers))
print('Number of followings:', len(following))
print('Number of nonFollowers:', len(nonFollow))
for i in range(number):
if i >= totalNonFollowers:
break
user = list(nonFollow.keys())[len(nonFollow)-1]
api.unfollow(nonFollow[user])
nonFollow.pop(user)
time.sleep(10)
if __name__ == "__main__":
unFollow(15)