-
Notifications
You must be signed in to change notification settings - Fork 4
/
dank.insta-tool.py
350 lines (259 loc) · 11.3 KB
/
dank.insta-tool.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import os
import time
import random
import instaloader
from instabot import Bot
import concurrent.futures
from alive_progress import alive_bar
from colorama import init, Fore, Style
os.system("title dank.insta-tool")
try:
filepath = os.path.dirname(__file__) # as .py
#filepath = os.path.dirname(sys.argv[0]) # as .exe
os.chdir(filepath)
try:os.mkdir("dank.insta-tool")
except:pass
os.chdir("dank.insta-tool")
except:pass
banner_ascii = '''
_ _ _ _ _ _
__| | __ _ _ __ | | __ (_)_ __ ___| |_ __ _ | |_ ___ ___ | |
/ _` |/ _` | '_ \| |/ / | | '_ \/ __| __/ _` |_____| __/ _ \ / _ \| |
| (_| | (_| | | | | < _| | | | \__ \ || (_| |_____| || (_) | (_) | |
\__,_|\__,_|_| |_|_|\_(_)_|_| |_|___/\__\__,_| \__\___/ \___/|_|
'''
# colors
init(autoreset=True)
red = Fore.RED + Style.BRIGHT
green = Fore.GREEN + Style.BRIGHT
magenta = Fore.MAGENTA + Style.BRIGHT
white = Fore.WHITE + Style.BRIGHT
# randomized banner color
bad_colors = ['BLACK', 'WHITE', 'LIGHTBLACK_EX', 'LIGHTWHITE_EX', 'RESET']
codes = vars(Fore)
colors = [codes[color] for color in codes if color not in bad_colors]
colored_chars = [random.choice(colors) + char for char in banner_ascii]
banner_colored = ''.join(colored_chars).splitlines()
# constants
def banner():
width = os.get_terminal_size().columns
banner_lines = banner_ascii.splitlines()
for i in range(len(banner_lines)):
banner_lines[i] = banner_lines[i].center(width).replace(banner_lines[i],banner_colored[i])
banner_aligned = ''.join(banner_lines)
return banner_aligned
def multithread(function, list):
futures = []
executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
for item in list:
futures.append(executor.submit(function, item))
with alive_bar(int(len(futures))) as bar:
for future in concurrent.futures.as_completed(futures):
try:
future.result()
bar()
except:
bar()
while True:
os.system('cls')
print(banner())
print(f"\n {white}> {magenta}1. Get and save {white}ghosts {magenta}/ {white}non-ghosts")
print(f"\n {white}> {magenta}2. Remove {white}ghost {magenta}followers")
print(f"\n {white}> {magenta}3. Bulk {white}unfollow")
print(f"\n {white}> {magenta}4. Exit")
choice = int(input(f"\n {white}> {magenta}Enter Choice{white}: {magenta}"))
def one():
login_username = str(input(f"\n {white}> {magenta}Enter your instagram username{white}: {magenta}")).lower()
# instaloader login
print("")
os.system(f"instaloader --login={login_username}")
L = instaloader.Instaloader()
L.load_session_from_file(login_username)
profile = instaloader.Profile.from_username(L.context, login_username)
os.system('cls')
print(banner())
# selected posts
# get usernames of likers and commenters on selected posts
print(f"\n {white}> {magenta}Getting {white}likers {magenta}and {white}commenters [ {magenta}this might take a while {white}]\n")
liked_users = []
commented_users = []
followers = []
def get_users(post):
post_likes = post.get_likes()
post_comments = post.get_comments()
for like in post_likes:
liked_users.append(str(like.username))
for comment in post_comments:
commented_users.append(str(comment.owner.username))
multithread(get_users, profile.get_posts())
# get usernames of your followers
print(f"\n {white}> {magenta}Getting {white}follower usernames...\n")
def get_follower_usernames(follower):
followers.append(str(follower.username))
multithread(get_follower_usernames, profile.get_followers())
# get ghosts and non ghosts
print(f"\n {white}> {magenta}Getting {white}ghosts {magenta}and {white}non_ghosts\n")
def find_non_ghosts():
non_ghosts = []
for user in followers:
if user in liked_users or user in commented_users:
non_ghosts.append(user)
return list(set(non_ghosts))
def find_ghosts():
ghosts = []
for user in followers:
if user not in non_ghosts:
ghosts.append(user)
return list(set(ghosts))
liked_users = list(set(liked_users))
commented_users = list(set(commented_users))
non_ghosts = find_non_ghosts()
ghosts = find_ghosts()
os.system('cls')
print(banner())
# save txt files
def create_txt(name):
try:
open(f"{name}.txt","x")
except:
pass
txt_files = ['likers','commenters','non_ghosts','ghosts','followers','removed_ghosts','unremoved_ghosts']
for name in txt_files:
create_txt(name)
print(f"\n {white}> {magenta}Saving {white}likers.txt")
open('likers.txt','w+').write('\n'.join(liked_users))
print(f"\n {white}> {magenta}Saving {white}commenters.txt")
open('commenters.txt','w+').write('\n'.join(commented_users))
print(f"\n {white}> {magenta}Saving {white}non_ghosts.txt")
open('non_ghosts.txt','w+').write('\n'.join(non_ghosts))
print(f"\n {white}> {magenta}Saving {white}ghosts.txt")
open('ghosts.txt','w+').write('\n'.join(ghosts))
print(f"\n {white}> {magenta}Saving {white}followers.txt")
open('followers.txt','w+').write('\n'.join(followers))
print(f"\n {white}> {magenta}Tasks Complete! Sleeping 10s...")
time.sleep(10)
def two():
# check if ghosts.txt exists
try:
ghosts = list(set(open("ghosts.txt","r").read().splitlines()))
except:
print(f" {white}> {red}The file {white}ghosts.txt {red}does not exist! Please use {white}option 1 {red}first before using {white}option 2{red}!")
print(f" {white}> {red}Going to menu in 5s...")
time.sleep(5)
return
bot = Bot()
while True:
try:
bot.login()
break
except Exception as e:
wait = input(f"\n {white}> {red}Failed! Press {white}ENTER {red}to try again! | {str(e)}")
removed_ghosts = []
unremoved_ghosts = []
# remove ghosts
def remove_follower(user):
errors = 0
while True:
try:
user_id = bot.get_user_id_from_username(user)
bot.api.remove_follower(user_id)
removed_ghosts.append(user)
print(f"\n {white}> {green}Removed {white}{user}{green}!")
time.sleep(.3)
break
except Exception as e:
errors += 1
if errors >= 4:
unremoved_ghosts.append(user)
print(f"\n {white}> {red}Failed {white}{user} {red}| {str(e)}")
break
print(f"\n {white}> {red}Retrying {white}{user}")
time.sleep(10)
os.system('cls')
print(banner())
print(f"\n {white}> {magenta}Removing {white}{len(ghosts)} ghosts...\n")
multithread(remove_follower, ghosts)
# save txt files
os.system('cls')
print(banner())
print(f"\n {white}> {magenta}Removed {white}{len(removed_ghosts)} {magenta}ghosts!")
print(f"\n {white}> {red}Failed to remove {white}{len(unremoved_ghosts)} {red}ghosts!")
print(f"\n {white}> {magenta}Saving {white}removed_ghosts.txt")
open('removed_ghosts.txt','w+').write('\n'.join(removed_ghosts))
print(f"\n {white}> {magenta}Saving {white}unremoved_ghosts.txt")
open('unremoved_ghosts.txt','w+').write('\n'.join(unremoved_ghosts))
print(f"\n {white}> {magenta}Tasks Complete! Sleeping 10s...")
time.sleep(10)
def three():
# check if to_unfollow.txt exists
try:
open("to_unfollow.txt","x")
print(f"\n {white}> {magenta}Created {white}to_unfollow.txt")
except:
print(f"\n {white}> {white}to_unfollow.txt {magenta}already exists!")
print(f"\n {white}> {magenta}Add usernames to {white}to_unfollow.txt {magenta}to bulk unfollow")
os.system("to_unfollow.txt")
wait = input(f"\n {white}> {magenta}Press Enter to begin...\n\n")
try:
to_unfollow = list(set(open("to_unfollow.txt","r").read().splitlines()))
except:
print(f" {white}> {red}The file {white}to_unfollow.txt {red}does not exist! Please create it and add username first before using {white}option 3{red}!")
print(f" {white}> {red}Going to menu in 5s...")
time.sleep(5)
return
bot = Bot()
while True:
try:
bot.login()
break
except Exception as e:
wait = input(f"\n {white}> {red}Failed! Press {white}ENTER {red}to try again! | {str(e)}")
unfollowed = []
failed_unfollow = []
# unfollow
def unfollow(user):
errors = 0
while True:
try:
user_id = bot.get_user_id_from_username(user)
bot.api.unfollow(user_id)
unfollowed.append(user)
print(f"\n {white}> {green}Unfollowed {white}{user}{green}!")
time.sleep(.3)
break
except Exception as e:
errors += 1
if errors >= 4:
failed_unfollow.append(user)
print(f"\n {white}> {red}Failed {white}{user} {red}| {str(e)}")
break
print(f"\n {white}> {red}Retrying {white}{user}")
time.sleep(10)
os.system('cls')
print(banner())
print(f"\n {white}> {magenta}Bulk {white}unfollowing {len(to_unfollow)} {magenta}users...\n")
multithread(unfollow, to_unfollow)
# save txt files
os.system('cls')
print(banner())
print(f"\n {white}> {magenta}Unfollowed {white}{len(unfollowed)} {magenta}users!")
print(f"\n {white}> {red}Failed to unfollow {white}{len(failed_unfollow)} {red}users!")
print(f"\n {white}> {magenta}Saving {white}unfollowed.txt")
open('unfollowed.txt','w+').write('\n'.join(unfollowed))
print(f"\n {white}> {magenta}Saving {white}failed_unfollow.txt")
open('failed_unfollow.txt','w+').write('\n'.join(failed_unfollow))
print(f"\n {white}> {magenta}Tasks Complete! Sleeping 10s...")
time.sleep(10)
# input
os.system('cls')
if choice == 1:
print(banner())
one()
elif choice == 2:
print(banner())
two()
elif choice == 3:
print(banner())
three()
elif choice == 4:
break