-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
317 lines (272 loc) · 8.76 KB
/
main.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
import codecs
import os
import random
import time
import telebot
from requests import post
from telebot.types import KeyboardButton, ReplyKeyboardMarkup
import aux_funcs
from API.InstagramAPI import InstagramAPI
from config import BOT_TOKEN
if BOT_TOKEN == "null":
BOT_TOKEN = input("Input your bot token: ")
followers = []
followings = []
### Delay in seconds ###
min_delay = 5
max_delay = 10
MAXIMO = 100
class User:
passw = None
name = None
API = None
session = telebot.TeleBot(BOT_TOKEN)
b1 = KeyboardButton("info")
b2 = KeyboardButton("super unfollow")
b3 = KeyboardButton("super followback")
b4 = KeyboardButton("unfollow all")
b5 = KeyboardButton("login account")
k1 = ReplyKeyboardMarkup(resize_keyboard=True)
k1.row(b1, b2, b5)
k1.row(b3, b4)
@session.message_handler(commands=["start"])
def start(self):
session.send_message(self.chat.id, "choose menu:", reply_markup=k1)
@session.message_handler()
def command(self):
if self.text == "info":
info()
text = codecs.open("dont_follow_me.txt", "r", encoding="utf-8")
paste_text = text.read()
try:
link = (
post(
"https://nekobin.com/api/documents",
json={"content": paste_text},
)
.json()
.get("result")
.get("key")
)
session.send_message(self.chat.id, f"https://nekobin.com/{link}")
os.remove("dont_follow_me.txt")
except Exception as e:
print(e)
elif self.text == "super unfollow":
super_unfollow()
text = codecs.open("super_unfollow.txt", "r", encoding="utf-8")
paste_text = text.read()
try:
link = (
post(
"https://nekobin.com/api/documents",
json={"content": paste_text},
)
.json()
.get("result")
.get("key")
)
session.send_message(self.chat.id, f"https://nekobin.com/{link}")
os.remove("super_unfollow.txt")
except Exception as e:
print(e)
elif self.text == "super followback":
super_followback()
text = codecs.open("super_followback.txt", "r", encoding="utf-8")
paste_text = text.read()
try:
link = (
post(
"https://nekobin.com/api/documents",
json={"content": paste_text},
)
.json()
.get("result")
.get("key")
)
session.send_message(self.chat.id, f"https://nekobin.com/{link}")
os.remove("super_followback.txt")
except Exception as e:
print(e)
elif self.text == "unfollow all":
unfollowall()
text = codecs.open("unfollowall.txt", "r", encoding="utf-8")
paste_text = text.read()
try:
link = (
post(
"https://nekobin.com/api/documents",
json={"content": paste_text},
)
.json()
.get("result")
.get("key")
)
session.send_message(self.chat.id, f"https://nekobin.com/{link}")
os.remove("unfollowall.txt")
except Exception as e:
print(e)
elif self.text == "login account":
name = session.reply_to(self, "Please enter your username:")
session.register_next_step_handler(name, passwx)
else:
session.send_message(self.chat.id, "Input invalid!")
def passwx(self):
User.name = self.text
User.chat_id = self.chat.id
passw = session.reply_to(self, "Please enter your password:")
session.register_next_step_handler(passw, process)
def process(self):
User.passw = self.text
session.send_message(self.chat.id, "Just a moment...")
User.API = InstagramAPI(username=User.name, password=User.passw)
start(self)
def info():
f = open("dont_follow_me.txt", "a")
f.write("I follow them but they dont follow me:\n")
tot = 0
for i in followings:
if i not in followers:
tot = tot + 1
f.write(str(tot) + " " + i)
f.write("\n")
f.write("\nTotal: " + str(tot))
f.write("\n\n")
f.write("\nThey follow me but i dont follow them:\n")
tot = 0
for i in followers:
if i not in followings:
tot = tot + 1
f.write(str(tot) + " " + i)
f.write("\n")
f.write("\nTotal: " + str(tot))
f.write("\n\n")
f.write("\nPeople following me:\n")
tot = 0
for i in followers:
tot = tot + 1
f.write(str(tot) + " " + i)
f.write("\n")
f.write("\nTotal: " + str(tot))
f.write("\n\n")
f.write("\nPeople I follow:\n")
tot = 0
for i in followings:
tot = tot + 1
f.write(str(tot) + " " + i)
f.write("\n")
f.write("\nTotal: " + str(tot))
def follow_tag(tag):
api.tagFeed(tag)
media_id = api.LastJson
tot = 0
print("\nTAG: " + str(tag) + "\n")
for i in media_id["items"]:
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
username = i.get("user")["username"]
user_id = i.get("user")["pk"]
User.API.follow(user_id)
tot += 1
print("Following " + str(username) + " (with id " + str(user_id) + ")")
if tot >= MAXIMO:
break
print(
"Total: " + str(tot) + " for tag " + tag + " (Max val: " + str(MAXIMO) + ")\n"
)
def follow_location(target):
api.getLocationFeed(target)
media_id = api.LastJson
tot = 0
for i in media_id.get("items"):
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
username = i.get("user").get("username")
user_id = aux_funcs.get_id(username)
User.API.follow(user_id)
tot += 1
f = open("follow_location.txt", "a")
f.write("Following " + str(username) + " (with id " + str(user_id) + ")")
f.write("\n")
if tot >= MAXIMO:
break
print(
"Total: "
+ str(tot)
+ " for location "
+ str(target)
+ " (Max val: "
+ str(MAXIMO)
+ ")\n"
)
def follow_list(target):
user_list = open(target).read().splitlines()
tot = 0
for username in user_list:
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
user_id = aux_funcs.get_id(username)
User.API.follow(user_id)
tot += 1
f = open("follow_list.txt", "a")
f.write("Following " + str(username) + " (with id " + str(user_id) + ")")
f.write("\n")
if tot >= MAXIMO:
break
print(
"Total: "
+ str(tot)
+ " users followed from "
+ str(target)
+ " (Max val: "
+ str(MAXIMO)
+ ")\n"
)
def super_followback():
count = 0
for i in followers:
if i not in followings:
count += 1
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
f = open("super_followback.txt", "a")
f.write(str(count) + ") Following back " + i)
f.write("\n")
user_id = aux_funcs.get_id(i)
User.API.follow(user_id)
def super_unfollow():
whitelist = open("whitelist.txt").read().splitlines()
count = 0
for i in followings:
if (i not in followers) and (i not in whitelist):
count += 1
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
f = open("super_unfollow.txt", "a")
f.write(str(count) + ") Unfollowing " + i)
f.write("\n")
user_id = aux_funcs.get_id(i)
User.API.unfollow(user_id)
def unfollowall():
whitelist = open("whitelist.txt").read().splitlines()
count = 0
for i in followings:
if i not in whitelist:
count += 1
time.sleep(float(random.uniform(min_delay * 10, max_delay * 10) / 10))
f = open("unfollowall.txt", "a")
f.write(str(count) + ") Unfollowing " + i)
f.write("\n")
user_id = aux_funcs.get_id(i)
User.API.unfollow(user_id)
def start(self):
try:
User.API.login()
for i in User.API.getTotalSelfFollowers():
followers.append(i.get("username"))
for i in User.API.getTotalSelfFollowings():
followings.append(i.get("username"))
session.send_message(self.chat.id, "Login successfully")
except Exception as e:
session.send_message(self.chat.id, f"Login Failed...\nLog: {e}")
if __name__ == "__main__":
try:
print("Started...!")
session.infinity_polling()
except Exception:
time.sleep(15)