clean buidl

This commit is contained in:
cupcakearmy 2019-02-16 15:44:18 +01:00
parent d06fff5bc4
commit bb8a9bfcda
29 changed files with 29 additions and 2313 deletions

3
.gitignore vendored
View File

@ -1,2 +1 @@
config.json config.json
data.db

18
Dockerfile Normal file
View File

@ -0,0 +1,18 @@
# Multi State
# Download and extract latest code
FROM alpine as GIT
ADD https://github.com/instabot-py/instabot.py/archive/master.zip /tmp
RUN unzip -q /tmp/master.zip
RUN cp -r instabot.py-master/src instabot.py-master/requirements.txt /tmp
FROM python:3-alpine
WORKDIR /app
COPY --from=GIT /tmp/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY --from=GIT /tmp/src ./src
COPY app.py .
CMD [ "python3", "-u", "app.py" ]

View File

@ -23,10 +23,11 @@ vim config.json
docker-compose up -d docker-compose up -d
``` ```
#### (Optional) Persist the DB 💽 ### (Default) Persist the DB 💽
Instabot saved the followers etc. in a sqlite db called `follows_db.db`. If you wish to persist the changes between updates you need to uncomment the line inside `docker-compose.yml` and run `touch data.db` before running `docker-compose up -d` By default the DB is persisted. Instabot saved the followers etc. in a sqlite db called `follows_db.db`. To start with a clean state you need to delete the `data.db` file.
Either run `rm data.db; touch data.db` or `cat /dev/null > data.db`.
### Credits ### Credits
The actual code for the bot is from https://github.com/instabot-py/instabot.py The actual code for the bot is from https://github.com/instabot-py/instabot.py

View File

View File

@ -1,13 +0,0 @@
FROM alpine:3.7
WORKDIR /app
RUN apk add --no-cache python3
RUN python3 -m pip install --upgrade pip
COPY ./requirements.txt .
RUN python3 -m pip install --no-cache-dir -r requirements.txt
COPY ./ .
CMD [ "python3", "-u", "./app.py" ]

View File

@ -1,3 +0,0 @@
requests
fake-useragent
instaloader

View File

@ -1 +0,0 @@
from .instabot import InstaBot

View File

@ -1,13 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .user_info import get_user_info
def check_status(self):
self.is_self_checking = True
self.is_checked = False
while self.is_checked != True:
get_user_info(self, self.user_login)
self.like_counter = 0
self.follow_counter = 0
self.unfollow_counter = 0

View File

@ -1,68 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from .likers_graber_protocol import likers_graber_protocol
from .new_auto_mod_unfollow2 import new_auto_mod_unfollow2
from .recent_feed import get_media_id_recent_feed
from .user_feed import get_media_id_user_feed
def feed_scanner(self):
#This is to limit how many people do you want to put into list before
##The bot start to check their profile one by one and start following them
limit = random.randint(51, 90)
while len(self.user_info_list) < limit:
#First the bot try to collect media id on your recent feed
get_media_id_recent_feed(self)
#If your account is old enough, there will be 10 photos on your recent feed
if len(self.media_on_feed) > 10:
#Select the media on your recent feed randomly
chooser = random.randint(0, len(self.media_on_feed) - 1)
#The bot will save the owner of the media name and use it to try checking his/her profile
self.current_user = self.media_on_feed[chooser]["node"]["owner"][
"username"]
self.current_id = self.media_on_feed[chooser]["node"]["owner"][
"id"]
#If your account is new, and you don't following anyone, your recent feed will be empty
else:
#If your recent feed is empty, then you start collecting media id by hashtag
self.is_by_tag = True
get_media_id_user_feed(self)
max_media = 0
while len(self.media_on_feed) > 5 and max_media < 5:
chooser = random.randint(0, len(self.media_on_feed) - 1)
self.current_id = self.media_on_feed[chooser]["node"]["owner"][
"id"]
self.follow(self.current_id)
self.media_on_feed[chooser] = None
max_media += 1
time.sleep(30)
self.is_by_tag = False
self.media_on_feed = []
if len(self.user_info_list) < 10000:
for index in range(len(self.ex_user_list)):
if self.ex_user_list[index][0] in self.current_user:
print(
'============================== \nUpss ' +
self.current_user +
' is already in ex user list... \n=============================='
)
break
else:
likers_graber_protocol(self)
self.ex_user_list.append([self.current_user, self.current_id])
self.user_list = []
self.media_by_user = []
self.media_on_feed = []
if len(self.ex_user_list) > 20:
chooser = random.randint(0, len(self.ex_user_list) - 1)
self.current_user = self.ex_user_list[chooser][0]
self.current_id = self.ex_user_list[chooser][1]
print('Trying to unfollow : ' + self.current_user)
new_auto_mod_unfollow2(self)
del self.ex_user_list[chooser]
time.sleep(random.randint(15, 22))

View File

@ -1,40 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from .feed_scanner import feed_scanner
from .user_info import get_user_info
def follow_protocol(self):
limit = random.randint(5, 10)
while self.follow_counter < limit:
chooser = 0
if len(self.user_info_list) > 0:
chooser = random.randint(0, len(self.user_info_list) - 1)
self.current_user = self.user_info_list[chooser][0]
self.current_id = self.user_info_list[chooser][1]
print('=============== \nCheck profile of ' + self.current_user +
'\n===============')
get_user_info(self, self.current_user)
else:
print('xxxxxxx user info list is empty!!! xxxxxxxxx')
feed_scanner(self)
if self.is_selebgram != True and self.is_fake_account != True and self.is_active_user != False:
if self.is_following != True:
log = ('Trying to follow : ' + self.current_user +
' with user ID :' + self.current_id)
self.write_log(log)
self.follow(self.current_id)
log = ('delete ' + self.user_info_list[chooser][0] +
' from user info list')
self.write_log(log)
del self.user_info_list[chooser]
else:
log = ('delete ' + self.user_info_list[chooser][0] +
' from user info list')
self.write_log(log)
del self.user_info_list[chooser]
time.sleep(random.randint(13, 26))

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from .likers_protocol import likers_protocol
from .new_auto_mod_unfollow2 import new_auto_mod_unfollow2
from .user_feed import get_media_id_user_feed
def likers_graber_protocol(self):
limit = random.randint(1, 3)
counterx = 0
self.is_checked = False
self.is_rejected = False
while counterx <= limit:
# ------------------- Get media_id -------------------
if len(self.media_by_user) == 0:
self.is_checked = False
self.is_rejected = False
get_media_id_user_feed(self)
# ------------------- Like -------------------
if self.is_rejected is not False:
self.is_checked = False
new_auto_mod_unfollow2(self)
return 0
likers_protocol(self)
time.sleep(random.randint(13, 35))
counterx += 1

View File

@ -1,25 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from .post_page import get_user_id_post_page
from .username_checker import username_checker
def likers_protocol(self):
if len(self.media_by_user) > 0:
# You have media_id to like:
self.current_index = random.randint(0, len(self.media_by_user) - 1)
log_string = "Current Index = %i of %i medias" % (
self.current_index, len(self.media_by_user))
self.write_log(log_string)
if self.media_by_user[self.current_index]["likes"]["count"] >= 10 \
and self.media_by_user[self.current_index]["likes"]["count"] < 100:
get_user_id_post_page(
self, self.media_by_user[self.current_index]["code"])
username_checker(self)
del self.media_by_user[self.current_index]

View File

@ -1,18 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
from .new_auto_mod_likeall import new_like_all_exist_media
def new_auto_mod_like2(self):
if len(self.media_by_user) > 0:
# You have media_id to like:
self.current_index = random.randint(0, len(self.media_by_user) - 1)
log_string = "Current Index = %i of %i medias" % (
self.current_index, len(self.media_by_user))
self.write_log(log_string)
new_like_all_exist_media(self)
# Del first media_id
del self.media_by_user[self.current_index]

View File

@ -1,33 +0,0 @@
import pprint
def new_like_all_exist_media(self):
i = self.current_index
# Media count by this user.
#print(*self.media_by_user[i]['node'])
#quit()
l_c = self.media_by_user[i]['node']['edge_liked_by']['count']
if l_c <= self.media_max_like and l_c >= self.media_min_like:
log_string = "Trying to like media: %s" %\
(self.media_by_user[i]['node']['id'])
self.write_log(log_string)
like = self.like(self.media_by_user[i]['node']['id'])
if like != 0:
if like.status_code == 200:
log_string = "Liked: %s. Likes: #%i." %\
(self.media_by_user[i]['node']['id'],
self.media_by_user[i]['node']['edge_liked_by']['count'])
self.write_log(log_string)
elif like.status_code == 400:
log_string = "Not liked: %i" \
% (like.status_code)
self.write_log(log_string)
else:
log_string = "Not liked: %i" \
% (like.status_code)
self.write_log(log_string)
return False
else:
return False
else:
print('Too many likes on this media LC = %i' % (l_c))
return True

View File

@ -1,9 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .new_unfollow import new_unfollow
def new_auto_mod_unfollow2(self):
log_string = "Trying to unfollow: %s" % (self.current_user)
self.write_log(log_string)
new_unfollow(self, self.current_id, self.current_user)

View File

@ -1,20 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .sql_updates import insert_unfollow_count
def new_unfollow(self, user_id, user_name):
""" Send http request to unfollow """
url_unfollow = self.url_unfollow % (user_id)
try:
unfollow = self.s.post(url_unfollow)
if unfollow.status_code == 200:
self.unfollow_counter += 1
log_string = "Unfollow: %s #%i." % (user_name,
self.unfollow_counter)
self.write_log(log_string)
insert_unfollow_count(self, user_id=user_id)
return unfollow
except:
self.write_log("Exept on unfollow!")
return False

View File

@ -1,26 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import time
def get_user_id_post_page(self, code):
if self.login_status:
log_string = 'Get user id on post page'
self.write_log(log_string)
url = 'https://www.instagram.com/p/%s/?__a=1' % (code)
try:
r = self.s.get(url)
all_data = json.loads(r.text)
self.user_list = list(all_data['graphql']['shortcode_media']['edge_media_preview_like']['edges'])
log_string = "User likes this post = %i" % (
all_data['graphql']['shortcode_media']['edge_media_preview_like']['count'])
self.write_log(log_string)
except:
self.media_on_feed = []
self.write_log("Except on get user list!!!!")
time.sleep(10)
return 0
else:
return 0

View File

@ -1,34 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import json
import time
import re
def get_media_id_recent_feed(self):
if self.login_status:
now_time = datetime.datetime.now()
log_string = "%s : Get media id on recent feed \n %s" % (
self.user_login, now_time.strftime("%d.%m.%Y %H:%M"))
self.write_log(log_string)
url = 'https://www.instagram.com/'
try:
r = self.s.get(url)
jsondata = re.search('additionalDataLoaded\(\'feed\',({.*})\);', r.text).group(1)
all_data = json.loads(jsondata.strip())
self.media_on_feed = list(all_data['user']['edge_web_feed_timeline']['edges'])
log_string = "Media in recent feed = %i" % (
len(self.media_on_feed))
self.write_log(log_string)
except:
self.media_on_feed = []
self.write_log('Except on get media!!')
time.sleep(20)
return 0
else:
return 0

View File

@ -1,174 +0,0 @@
# -*- coding: utf-8 -*-
import sqlite3
from datetime import datetime, time, timedelta
def check_and_update(self):
""" At the Program start, i does look for the sql updates """
self.follows_db_c.execute("CREATE TABLE IF NOT EXISTS usernames (username varchar(300))")
self.follows_db_c.execute("CREATE TABLE IF NOT EXISTS medias (media_id varchar(300))")
table_info = self.follows_db_c.execute("pragma table_info(medias)")
table_column_status = [o for o in table_info if o[1] == "status"]
if not table_column_status:
self.follows_db_c.execute("ALTER TABLE medias ADD COLUMN status integer")
table_info = self.follows_db_c.execute("pragma table_info(medias)")
table_column_status = [o for o in table_info if o[1] == "datetime"]
if not table_column_status:
self.follows_db_c.execute("ALTER TABLE medias ADD COLUMN datetime TEXT")
table_info = self.follows_db_c.execute("pragma table_info(medias)")
table_column_status = [o for o in table_info if o[1] == "code"]
if not table_column_status:
self.follows_db_c.execute("ALTER TABLE medias ADD COLUMN code TEXT")
table_info = self.follows_db_c.execute("pragma table_info(usernames)")
table_column_status = [o for o in table_info if o[1] == "username_id"]
if not table_column_status:
qry = """
CREATE TABLE "usernames_new" ( `username_id` varchar ( 300 ), `username` TEXT );
INSERT INTO "usernames_new" (username) Select username from usernames;
DROP TABLE "usernames";
ALTER TABLE "usernames_new" RENAME TO "usernames";
"""
self.follows_db_c.executescript(qry)
table_info = self.follows_db_c.execute("pragma table_info(usernames)")
table_column_status = [o for o in table_info if o[1] == "unfollow_count"]
if not table_column_status:
self.follows_db_c.execute("ALTER TABLE usernames ADD COLUMN unfollow_count INTEGER DEFAULT 0")
table_info = self.follows_db_c.execute("pragma table_info(usernames)")
table_column_status = [o for o in table_info if o[1] == "last_followed_time"]
if not table_column_status:
self.follows_db_c.execute("ALTER TABLE usernames ADD COLUMN last_followed_time TEXT")
table_info = self.follows_db_c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='settings';").fetchone()
if not table_info:
qry = """
CREATE TABLE "settings" ( `settings_name` TEXT, `settings_val` TEXT );
"""
self.follows_db_c.execute(qry)
#table_column_status = [o for o in table_info if o[1] == "last_followed_time"]
#if not table_column_status:
# self.follows_db_c.execute("ALTER TABLE usernames ADD COLUMN last_followed_time TEXT")
def check_already_liked(self, media_id):
""" controls if media already liked before """
if self.follows_db_c.execute("SELECT EXISTS(SELECT 1 FROM medias WHERE media_id='"+
media_id + "' LIMIT 1)").fetchone()[0] > 0:
return 1
return 0
def check_already_followed(self, user_id):
""" controls if user already followed before """
if self.follows_db_c.execute("SELECT EXISTS(SELECT 1 FROM usernames WHERE username_id='"+
user_id + "' LIMIT 1)").fetchone()[0] > 0:
return 1
return 0
def check_already_unfollowed(self, user_id):
""" controls if user was already unfollowed before """
if self.follows_db_c.execute("SELECT EXISTS(SELECT 1 FROM usernames WHERE username_id='"+
user_id + "' AND unfollow_count > 0 LIMIT 1)").fetchone()[0] > 0:
return 1
return 0
def insert_media(self, media_id, status):
""" insert media to medias """
now = datetime.now()
self.follows_db_c.execute("INSERT INTO medias (media_id, status, datetime) VALUES('"+
media_id +"','"+ status +"','"+ str(now) +"')")
def insert_username(self, user_id, username):
""" insert user_id to usernames """
now = datetime.now()
self.follows_db_c.execute("INSERT INTO usernames (username_id, username, last_followed_time) \
VALUES('"+user_id+"','"+username+"','"+ str(now) +"')")
def insert_unfollow_count(self, user_id=False, username=False):
""" track unfollow count for new futures """
if user_id:
qry = "UPDATE usernames \
SET unfollow_count = unfollow_count + 1 \
WHERE username_id ='"+user_id+"'"
self.follows_db_c.execute(qry)
elif username:
qry = "UPDATE usernames \
SET unfollow_count = unfollow_count + 1 \
WHERE username ='"+username+"'"
self.follows_db_c.execute(qry)
else:
return False
def get_usernames_first(self):
""" Gets first element of usernames table """
username = self.follows_db_c.execute("SELECT * FROM usernames LIMIT 1")
if username:
return username
else:
return False
def get_usernames(self):
""" Gets usernames table """
usernames = self.follows_db_c.execute("SELECT * FROM usernames")
if usernames:
return usernames
else:
return False
def get_username_random(self):
""" Gets random username """
username = self.follows_db_c.execute("SELECT * FROM usernames WHERE unfollow_count=0 ORDER BY RANDOM() LIMIT 1").fetchone()
if username:
return username
else:
return False
def get_username_to_unfollow_random(self):
""" Gets random username that is older than follow_time and has zero unfollow_count """
now_time = datetime.now()
cut_off_time = now_time - timedelta(seconds=self.follow_time)
username = self.follows_db_c.execute("SELECT * FROM usernames WHERE \
DATETIME(last_followed_time) < DATETIME('"+str(cut_off_time)+"') \
AND unfollow_count=0 ORDER BY RANDOM() LIMIT 1").fetchone()
if username:
return username
else:
username = self.follows_db_c.execute("SELECT * FROM usernames WHERE \
unfollow_count=0 ORDER BY RANDOM() LIMIT 1").fetchone()
if username:
return username
else:
return False
def get_username_row_count(self):
""" Gets the number of usernames in table """
count = self.follows_db_c.execute("select count(*) from usernames").fetchone()
if count:
return count[0]
else:
return False
def check_if_userid_exists(self, userid):
""" Checks if username exists """
#print("select count(*) from usernames WHERE username_id = " + userid)
count = self.follows_db_c.execute("select count(*) from usernames WHERE username_id = " + userid).fetchone()
if count:
if count[0] > 0:
return True
else:
return False
else:
return False
def check_and_insert_user_agent(self, user_agent):
""" Check user agent """
qry = "SELECT settings_val from settings where settings_name = 'USERAGENT'"
result_check = self.follows_db_c.execute(qry).fetchone()
if result_check:
result_get = result_check[0]
return result_get
else:
qry_insert = """
INSERT INTO settings (settings_name, settings_val)
VALUES ('USERAGENT', '%s')
""" % user_agent
self.follows_db_c.execute(qry_insert)
return check_and_insert_user_agent(self, user_agent)

View File

@ -1,42 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from .follow_protocol import follow_protocol
from .new_auto_mod_unfollow2 import new_auto_mod_unfollow2
from .recent_feed import get_media_id_recent_feed
from .user_feed_protocol import user_feed_protocol
def unfollow_protocol(self):
limit = random.randint(10, 22) + 1
while self.unfollow_counter <= limit:
get_media_id_recent_feed(self)
if len(self.media_on_feed) == 0:
self.follow_counter = 0
follow_protocol(self)
if len(self.media_on_feed) != 0 and self.is_follower_number < 5:
chooser = random.randint(0, len(self.media_on_feed) - 1)
self.current_user = self.media_on_feed[chooser]["node"]["owner"][
"username"]
self.current_id = self.media_on_feed[chooser]["node"]["owner"][
"id"]
if self.bot_mode == 2:
new_auto_mod_unfollow2(self)
time.sleep(30)
return
user_feed_protocol(self)
self.like_counter = 0
self.media_by_user = []
if self.is_selebgram is not False or self.is_fake_account is not False or self.is_active_user is not True or self.is_follower is not True:
new_auto_mod_unfollow2(self)
try:
del self.media_on_feed[chooser]
except:
self.media_on_feed = []
else:
follow_protocol(self)
self.is_follower_number = 0
time.sleep(13 + 5)

View File

@ -1,54 +0,0 @@
import random
import time
from .instabot import InstaBot
from .userinfo import UserInfo
#use userinfo
ui = UserInfo()
ui.search_user(user_name="login")
#take following
ui.get_following()
following = ui.following
#take followers
ui.get_followers()
followers = ui.followers
#favorite id list
favorites = ['111', '222', '333']
#some lists
newlist = []
endlist = []
followerslist = []
#get following id
for item in following:
newlist.append(item['id'])
#get followers id
for item in followers:
followerslist.append(item['id'])
#create final list with followers
endlist = set.difference(set(newlist), set(favorites), set(followerslist))
#create final list without followers
'''
endlist = set.difference(set(newlist), set(favorites))
'''
#use instabot
bot = InstaBot('login', 'password')
print('Number of unnecessary subscriptions:', len(endlist), '\n')
for items in endlist:
rnd = random.randint(1, 16)
bot.unfollow(items)
print('Wait', 30 + rnd, 'sec')
time.sleep(30 + rnd)
print('All done.')

View File

@ -1,39 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import random
import time
from .user_info import get_user_info
def get_media_id_user_feed(self):
if self.login_status:
if self.is_by_tag != True:
log_string = "======> Get media id by user: %s <======" % (
self.current_user)
if self.is_checked != True:
get_user_info(self, self.current_user)
if self.is_fake_account != True and self.is_active_user != False and self.is_selebgram != True or self.is_by_tag != False:
url = 'https://www.instagram.com/%s/' % (self.current_user)
self.write_log(log_string)
if self.login_status == 1 and self.is_fake_account != True and self.is_active_user != False and self.is_selebgram != True or self.is_by_tag != False:
try:
self.media_by_user = list(self.current_user_info['edge_owner_to_timeline_media']['edges'])
log_string = "Get media by user success!"
self.write_log(log_string)
except:
self.media_by_user = []
self.write_log("XXXXXXX Except on get_media! XXXXXXX")
time.sleep(60)
return 0
else:
log_string = "Reject this account \n=================== \nReason : \n Is Selebgram : %s \n Is Fake Account : %s \n Is Active User : %s \n" % (
self.is_selebgram, self.is_fake_account, self.is_active_user)
self.write_log(log_string)
self.is_rejected = True
self.media_by_user = []
self.media_on_feed = []
return 0

View File

@ -1,31 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import time
from .new_auto_mod_like2 import new_auto_mod_like2
from .user_feed import get_media_id_user_feed
def user_feed_protocol(self):
#To limit how many photos to scan
limit = random.randint(4, 6)
counterz = 0
self.is_checked = False
self.is_rejected = False
while counterz <= limit:
# ------------------- Get media_id -------------------
if len(self.media_by_user) is 0:
get_media_id_user_feed(self)
# ------------------- Like -------------------
if self.is_rejected is not False:
return 0
if self.is_follower is not False:
print(
"This is your follower")
self.is_follower_number += 1
time.sleep(5)
return
new_auto_mod_like2(self)
counterz += 1
time.sleep(3 * 15)

View File

@ -1,88 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import json
import random
import time
import re
def get_user_info(self, username):
current_user = username
log_string = "Getting user info : %s" % current_user
self.write_log(log_string)
if self.login_status == 1:
url_tag = self.url_user_detail % (current_user)
if self.login_status == 1:
r = self.s.get(url_tag)
if r.text.find('The link you followed may be broken, or the page may have been removed.') != -1:
log_string = "Looks like account was deleted, skipping : %s" % current_user
self.write_log(log_string)
insert_unfollow_count(self, user_id=current_id)
time.sleep(3)
return False
all_data = json.loads(re.search('window._sharedData = (.*?);</script>', r.text, re.DOTALL).group(1))['entry_data']['ProfilePage'][0]
user_info = all_data['graphql']['user']
self.current_user_info = user_info
i = 0
log_string = "Checking user info.."
self.write_log(log_string)
follows = user_info['edge_follow']['count']
follower = user_info['edge_followed_by']['count']
media = user_info['edge_owner_to_timeline_media']['count']
follow_viewer = user_info['follows_viewer']
followed_by_viewer = user_info[
'followed_by_viewer']
requested_by_viewer = user_info[
'requested_by_viewer']
has_requested_viewer = user_info[
'has_requested_viewer']
log_string = "Follower : %i" % (follower)
self.write_log(log_string)
log_string = "Following : %s" % (follows)
self.write_log(log_string)
log_string = "Media : %i" % (media)
self.write_log(log_string)
if follows == 0 or follower / follows > 2:
self.is_selebgram = True
self.is_fake_account = False
self.write_log(' >>>This is probably Selebgram account')
elif follower == 0 or follows / follower > 2:
self.is_fake_account = True
self.is_selebgram = False
self.write_log(' >>>This is probably Fake account')
else:
self.is_selebgram = False
self.is_fake_account = False
self.write_log(' >>>This is a normal account')
if media > 0 and follows / media < 25 and follower / media < 25:
self.is_active_user = True
self.write_log(' >>>This user is active')
else:
self.is_active_user = False
self.write_log(' >>>This user is passive')
if follow_viewer or has_requested_viewer:
self.is_follower = True
self.write_log(" >>>This account is following you")
else:
self.is_follower = False
self.write_log(' >>>This account is NOT following you')
if followed_by_viewer or requested_by_viewer:
self.is_following = True
self.write_log(' >>>You are following this account')
else:
self.is_following = False
self.write_log(' >>>You are NOT following this account')
else:
logging.exception("Except on auto_unfollow!")
time.sleep(3)
return False
else:
return 0

View File

@ -1,158 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import requests
import re
class UserInfo:
'''
This class try to take some user info (following, followers, etc.)
'''
user_agent = ("Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36")
url_user_info = "https://www.instagram.com/%s/"
url_list = {
"ink361": {
"main": "http://ink361.com/",
"user": "http://ink361.com/app/users/%s",
"search_name": "https://data.ink361.com/v1/users/search?q=%s",
"search_id": "https://data.ink361.com/v1/users/ig-%s",
"followers": "https://data.ink361.com/v1/users/ig-%s/followed-by",
"following": "https://data.ink361.com/v1/users/ig-%s/follows",
"stat": "http://ink361.com/app/users/ig-%s/%s/stats"
}
}
def __init__(self, info_aggregator="ink361"):
self.i_a = info_aggregator
self.hello()
def hello(self):
self.s = requests.Session()
self.s.headers.update({'User-Agent': self.user_agent})
main = self.s.get(self.url_list[self.i_a]["main"])
if main.status_code == 200:
return True
return False
def get_user_id_by_login(self, user_name):
url_info = self.url_user_info % (user_name)
info = self.s.get(url_info)
json_info = json.loads(re.search('window._sharedData = (.*?);</script>', info.text, re.DOTALL).group(1))
id_user = json_info['entry_data']['ProfilePage'][0]['graphql']['user']['id']
return id_user
def search_user(self, user_id=None, user_name=None):
'''
Search user_id or user_name, if you don't have it.
'''
self.user_id = user_id or False
self.user_name = user_name or False
if not self.user_id and not self.user_name:
# you have nothing
return False
elif self.user_id:
# you have just id
search_url = self.url_list[self.i_a]["search_id"] % self.user_id
elif self.user_name:
# you have just name
search_url = self.url_list[self.i_a][
"search_name"] % self.user_name
else:
# you have id and name
return True
search = self.s.get(search_url)
if search.status_code == 200:
r = json.loads(search.text)
if self.user_id:
# you have just id
self.user_name = r["data"]["username"]
else:
for u in r["data"]:
if u["username"] == self.user_name:
t = u["id"].split("-")
self.user_id = t[1]
# you have just name
return True
return False
def get_followers(self, limit=-1):
self.followers = None
self.followers = []
if self.user_id:
next_url = self.url_list[self.i_a]["followers"] % self.user_id
while True:
followers = self.s.get(next_url)
r = json.loads(followers.text)
for u in r["data"]:
if limit > 0 or limit < 0:
self.followers.append({
"username": u["username"],
#"profile_picture": u["profile_picture"],
"id": u["id"].split("-")[1],
#"full_name": u["full_name"]
})
limit -= 1
else:
return True
if r["pagination"]["next_url"]:
# have more data
next_url = r["pagination"]["next_url"]
else:
# end of data
return True
return False
def get_following(self, limit=-1):
self.following = None
self.following = []
if self.user_id:
next_url = self.url_list[self.i_a]["following"] % self.user_id
while True:
following = self.s.get(next_url)
r = json.loads(following.text)
for u in r["data"]:
if limit > 0 or limit < 0:
self.following.append({
"username": u["username"],
#"profile_picture": u["profile_picture"],
"id": u["id"].split("-")[1],
#"full_name": u["full_name"]
})
limit -= 1
else:
return True
if r["pagination"]["next_url"]:
# have more data
next_url = r["pagination"]["next_url"]
else:
# end of data
return True
return False
def get_stat(self, limit):
# todo
return False
'''
# example
ui = UserInfo()
# search by user_name:
ui.search_user(user_name="danbilzerian")
# or if you know user_id ui.search_user(user_id="50417061")
print(ui.user_name)
print(ui.user_id)
# get following list with no limit
ui.get_following()
print(ui.following)
# get followers list with limit 10
ui.get_followers(limit=10)
print(ui.followers)
'''

View File

@ -1,31 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def username_checker(self):
chooser = 0
while len(self.user_list) > 0 and chooser < len(self.user_list):
self.current_user = self.user_list[chooser]["node"]["username"]
self.current_id = self.user_list[chooser]["node"]["id"]
for index in range(len(self.unwanted_username_list)):
if self.unwanted_username_list[index] in self.current_user:
print('Username = ' + self.current_user + '\n ID = ' +
self.current_id + ' <<< rejected ' +
self.unwanted_username_list[index] + ' is found!!!')
break
else:
for index in range(len(self.user_info_list)):
if self.current_user in self.user_info_list[index][0]:
print(
'Username = ' + self.current_user + '\n ID = ' +
self.current_id +
' <<< rejected this user is already in user info list!!!'
)
break
else:
print('Username = ' + self.current_user + '\n ID = ' +
self.current_id + ' <<< added to user info list')
self.user_info_list.append(
[self.current_user, self.current_id])
chooser += 1
log_string = "\nSize of user info list : %i Size of ex user list : %i \n" % (
len(self.user_info_list), len(self.ex_user_list))
self.write_log(log_string)

0
data.db Normal file
View File

View File

@ -2,11 +2,13 @@ version: '3.6'
services: services:
instabot: instabot:
build: ./bot image: cupcakearmy/instabot
restart: always restart: always
container_name: instabot container_name: instabot
volumes: volumes:
# Uncomment if you want to save the db. # To reset the DB delete and create the data.db file
# In that case run `touch data.db` before running the container! # rm data.db; touch data.db;
# - ./data.db:/app/follows_db.db # or
# cat /dev/null > data.db
- ./data.db:/app/follows_db.db
- ./config.json:/app/config.json:ro - ./config.json:/app/config.json:ro