forked from tmhlsky/Instagram-API-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunfollow.py
More file actions
50 lines (38 loc) · 1.16 KB
/
Copy pathunfollow.py
File metadata and controls
50 lines (38 loc) · 1.16 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Use text editor to edit the script and type in valid Instagram username/password
import random
import time
from InstagramAPI import InstagramAPI
api = InstagramAPI("shapran.irina", "585925")
usersToUnfollow = []
def get_all_unfollowed_users():
my_followers = api.getTotalSelfFollowers()
i_follow = api.getTotalFollowings(api.username_id)
for following in i_follow:
flag = True
for follower in my_followers:
if follower['username'] == following['username']:
flag = False
break
if flag:
usersToUnfollow.append(following)
print("Number of non-following users: " + str(len(usersToUnfollow)))
def smart_sleep():
time.sleep(random.randint(2, 10))
def unfollow_users(max_users=118):
i = 1
for user in usersToUnfollow[:max_users]:
print(str(i) + " of " + str(max_users))
api.unfollow(user['pk'])
smart_sleep()
i += 1
def login():
if api.login():
get_all_unfollowed_users()
# unfollow_users(280)
else:
print("Can't login!")
if __name__ == '__main__':
login()