-
Notifications
You must be signed in to change notification settings - Fork 11
/
instaBot.py
75 lines (58 loc) · 2.07 KB
/
instaBot.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
from InstagramAPI import InstagramAPI
from config import password
import pprint
from time import sleep
users_list = []
following_users = []
follower_users = []
class InstaBot:
def __init__(self):
self.api = InstagramAPI("testingggggit123",password)
def get_likes_list(self,username):
api = self.api
api.login()
api.searchUsername(username)
result = api.LastJson
username_id = result['user']['pk']
user_posts = api.getUserFeed(username_id)
result = api.LastJson
media_id = result['items'][0]['id']
api.getMediaLikers(media_id)
users = api.LastJson['users']
for user in users:
users_list.append({'pk':user['pk'], 'username':user['username']})
pprint.pprint(users_list)
def follow_users(self,users_list):
api = self.api
api.login()
api.getSelfUsersFollowing()
result = api.LastJson
for user in result['users']:
following_users.append(user['pk'])
for user in users_list:
if user['pk'] in following_users:
print("Bot is already following @"+user['username'])
else:
print("Bot is now following @"+user['username'])
api.follow(user['pk'])
sleep(20)
def unfollow_users(self):
api = self.api
api.login()
api.getSelfUserFollowers()
result = api.LastJson
for user in result['users']:
follower_users.append({'pk':user['pk'],'username':user['username']})
api.getSelfUsersFollowing()
result = api.LastJson
for user in result['users']:
following_users.append({'pk':user['pk'],'username':user['username']})
for user in following_users:
if not user['pk'] in follower_users:
print("Unfollowing @"+user['username'])
api.unfollow(user['pk'])
sleep(20)
my_bot = InstaBot()
# my_bot.get_likes_list("instagram")
# my_bot.follow_users(users_list)
my_bot.unfollow_users()