This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_tags.py
171 lines (145 loc) · 5.23 KB
/
check_tags.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
import os
import sys
import argparse
from sys import platform # mac or linux
import huepy # for color print
from datetime import datetime
from tqdm import tqdm
hello = '''
_________________________________________
INSTAGRAM TAG checker by @kirillovmr
_________________________________________
'''
print(hello)
if "darwin" in platform.lower():
print("\tЗапущено на платформе MAC OS\n")
path_ = "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/instabot"
elif "linux" in platform.lower():
print("\tЗапущено на платформе LINUX\n")
path_ = "/usr/local/lib/python3.5/dist-packages/instabot"
elif "win32" in platform.lower():
print("\tЗапущено на платформе WINDOWS\n")
path_ = "c:\\users\\user\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\instabot"
else:
print("This platform is not supported. Exiting...")
exit()
def console_print(text, color=None):
if color is not None:
text = getattr(huepy, color)(text)
print(text)
sys.path.append(path_)
from instabot import Bot, utils
login = "_friendly_company"
password = "arina4ever699516"
proxy = "http://oxanaroma:A0z2CkV@31.41.219.235:65233"
post_link = "https://www.instagram.com/p/"
result_filename = 'result.txt'
vip_filename = 'vip.txt'
# Creating folders
dir = "{}/accs/{}/a".format(path_, login)
dir0 = "{}/accs/{}".format(path_, login)
if not os.path.exists(dir):
os.makedirs(dir)
if not os.path.exists(dir0 + '/tags'):
os.makedirs(dir0 + '/tags')
# Changing directory to instabot/accs/bot_id
os.chdir(dir)
bot = Bot()
bot.login(username=login, password=password, proxy=proxy)
# Creating dict of bad users
bad_users = {}
# Loading id -> username dict
followers_id_name = {}
try:
f = open('usernames.txt', 'r')
for line in f:
split = line.split(':')
id = split[0]
# обрезаем \n
split2 = split[1].split('\n')
username = split2[0]
followers_id_name[id] = username
f.close()
except:
print("Loaded file with usernames was not found.")
# Get list of VIP Users
vip = bot.read_list_from_file('../' + vip_filename)
# Deleting repeated items
vip = list(set(vip))
# Converting usernames to id
vip_id = []
for v in vip:
vip_id.append(bot.convert_to_user_id(v))
# Getting followers
followers = bot.followers
# Removing vip users from followers
users_to_check = [x for x in followers if x not in vip_id]
h = bot.get_user_tags_medias(bot.get_user_id_from_username(login))
# Deleting repeated items
posts = list(set(h))
# users_to_check = users_to_check[0:180]
# posts = posts[0:10]
# Получаем список лайков под всеми фото в хештеге
new_posts = []
for post in tqdm(posts, desc="Получаем список лайков"):
new_posts.append({'post': post, 'likers': bot.get_media_likers(post)})
# for user in users_to_check:
for user in tqdm(users_to_check, desc="Проверяем лайки"):
for post in new_posts:
likers = post['likers']
try:
likers.index(user)
except ValueError:
try:
bad_users[user]["num"] += 1
if(len(bad_users[user]["proof"]) < 2):
bad_users[user]["proof"].append(post['post'])
except KeyError:
bad_users[user] = {}
bad_users[user]["username"] = user
bad_users[user]["num"] = 1
bad_users[user]["proof"] = []
bad_users[user]["proof"].append(post['post'])
madiaid_code = {}
# [PROOF] Convert media id to link
for u in tqdm(bad_users, desc="Конвертация"):
id = bad_users[u]["username"]
try:
username = followers_id_name[id]
except KeyError:
username = bot.get_username_from_user_id(id)
followers_id_name[id] = username
bad_users[u]["username"] = username
proofs_link = []
for post_id in bad_users[u]["proof"]:
try:
code = madiaid_code[post_id]
except KeyError:
media_info = bot.get_media_info(post_id)
code = media_info[0]['code']
madiaid_code[post_id] = code
proofs_link.append(post_link + code)
bad_users[u]["proof"] = proofs_link
# Saving usernames dict
f = open('usernames.txt', 'w')
for u in followers_id_name:
try:
f.write(u + ':' + followers_id_name[u] + '\n')
except TypeError:
print("Cant write {}:{} in followers.txt".format(u, followers_id_name[u]))
f.close()
# Export results in file
date = datetime.today().strftime("%d.%m.%Y %H;%M")
result_filename = date + '.txt'
f = open('../tags/' + result_filename, 'w')
f.write("Отчет по фото со мной\n")
f.write("Сгенерирован {}\n\n".format(date))
for u in bad_users:
f.write("{} - {} пропусков.\n".format(bad_users[u]['username'], bad_users[u]['num']))
for proof in bad_users[u]["proof"]:
f.write(proof + '\n')
f.write('\n\n')
f.close()
console_print('\n\tКоличество аккаунтов не выполнивших условия: {}\n'.format(len(bad_users)), color='purple')
console_print('Результаты сохранены в файле {}\n'.format(result_filename), color='purple')
input("")