def get_followers(self, username, followers_list):
        self.bot.logger.info("Getting all followers of {}".format(username))
        current_followers = self.bot.get_user_followers(username)
        save_followers = utils.file(followers_list)
        if not save_followers.list:
            save_followers.save_list(current_followers)
            self.bot.logger.info(
                "{} file didn't exist. Creating file".format(followers_list))
            self.bot.logger.info("File {} created".format(followers_list))
            self.bot.logger.info(
                'Followers saved for first time in file {}'.format(
                    followers_list))
            self.bot.logger.info("Get followers has been completed")
            exit(0)

        with open(followers_list, 'r') as f:
            self.bot.logger.info("File {} exist".format(followers_list))
            self.bot.logger.info("Reading followers of the file")
            saved_followers = [x.strip('\n') for x in f.readlines()]

        if (len(current_followers) > 0):
            self.bot.logger.info(
                "Comparing followers saved between current followers")
            new_followers = [
                x for x in current_followers if x not in saved_followers
            ]
            unfollowers = [
                x for x in saved_followers if x not in current_followers
            ]
            self.bot.logger.info("Get followers has been completed")
            return (current_followers, new_followers, unfollowers)
        self.bot.logger.info(
            "Error. Problem with connection. No followers returned")
        return (saved_followers, [], [])
    def save_followers(self, username, followers_list, followers_log):
        self.bot.logger.info(
            "Saving all followers in log file {}".format(followers_log))
        datetime = time.strftime("%d-%m-%Y %H:%M:%S")
        (followers, new_followers,
         unfollowers) = self.get_followers(username, followers_list)
        lines = []
        with open(followers_log, 'a') as file:
            lines.append("===================================\n")
            lines.append(datetime + "\n")
            lines.append("===================================\n")
            lines.append("News: {}\n".format(len(new_followers)))
            lines.append("-----\n")
            for new in new_followers:
                lines.append(new + "\n")
            lines.append("------------------\n")
            lines.append("Unfollow me: {}\n".format(len(unfollowers)))
            lines.append("-----\n")
            for unfollow in unfollowers:
                lines.append(unfollow + "\n")
            lines.append("------------------\n")
            lines.append("Total: {}\n".format(len(followers)))
            lines.append("-----\n")
            for follow in followers:
                lines.append(follow + "\n")

            for item in lines:
                file.write(item)
            followers_list = utils.file(followers_list)
            followers_list.save_list(followers)
            return (followers, new_followers, unfollowers)
        return False
Beispiel #3
0
 def test_get_comment(self, comments):
     fname = tempfile.mkstemp()[1]  # Temporary file
     self.bot.comments_file = utils.file(fname, verbose=True)
     if comments:
         for comment in comments:
             self.bot.comments_file.append(comment)
         assert self.bot.get_comment() in self.bot.comments_file.list
     else:
         assert self.bot.get_comment() == 'Wow!'
def get_not_used_medias_from_users(bot, users=None, users_path=USERNAME_DATABASE):
    if not users:
        users = utils.file(users_path).list
    users = map(str, users)
    total_medias = []
    for user in users:
        medias = bot.get_user_medias(user, filtration=False)
        medias = [media for media in medias if not exists_in_posted_medias(media)]
        total_medias.extend(medias)
    return total_medias
Beispiel #5
0
def welcome_message():
    import argparse
    import os
    import sys
    from tqdm import tqdm

    sys.path.append(os.path.join(sys.path[0], '../'))
    from instabot import Bot, utils

    NOTIFIED_USERS_PATH = 'notified_users.txt'

    MESSAGE = 'Hi, this dr was send by BOT'

    parser = argparse.ArgumentParser(add_help=True)
    parser.add_argument('-users',
                        type=str,
                        nargs='?',
                        help='a path to already notified users')
    parser.add_argument('-message', type=str, nargs='?', help='message text')
    args = parser.parse_args()

    # Use custom message from args if exist
    if args.message:
        MESSAGE = args.message

    # Check on existed file with notified users
    notified_users = utils.file(NOTIFIED_USERS_PATH)
    if not notified_users.list:
        notified_users.save_list(bot.followers)
        print(
            'All followers saved in file {users_path}.\n'
            'In a next time, for all new followers script will send messages.'.
            format(users_path=NOTIFIED_USERS_PATH))
        exit(0)

    print('Read saved list of notified users. Count: {count}'.format(
        count=len(notified_users)))
    all_followers = bot.followers
    print(
        'Amount of all followers is {count}'.format(count=len(all_followers)))

    new_followers = set(all_followers) - notified_users.set

    if not new_followers:
        print('New followers not found')
        exit()

    print(
        'Found new followers. Count: {count}'.format(count=len(new_followers)))

    for follower in tqdm(new_followers):
        if bot.send_message(MESSAGE, follower):
            notified_users.append(follower)
Beispiel #6
0
def search_bots(self):
    self.logger.info("Searching bots...")
    your_followers = self.get_user_followers('276887698')
    bots = []
    for user in tqdm(your_followers[-500:]):
        if not self.check_not_bot(user):
            self.logger.info("Found bot: "
                             "https://instagram.com/%s/" %
                             self.get_user_info(user)["username"])
            bots.append(user)
    botsFile = utils.file("myBotFollowers.txt")
    botsFile.save_list(bots)
Beispiel #7
0
def get_not_used_medias_from_users(bot,
                                   users=None,
                                   users_path=USERNAME_DATABASE):
    if not users:
        if os.stat(USERNAME_DATABASE).st_size == 0:
            bot.logger.warning("No username(s) in thedatabase")
            sys.exit()
        elif os.path.exists(USERNAME_DATABASE):
            users = utils.file(users_path).list
        else:
            bot.logger.warning("No username database")
            sys.exit()

    total_medias = []
    user = random.choice(users)

    medias = bot.get_user_medias(user, filtration=False)
    medias = [media for media in medias if not exists_in_posted_medias(media)]
    total_medias.extend(medias)
    return total_medias
"""
    instabot example

    Workflow:
        Save users' following into a file.
"""
import os
import sys
import argparse

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot, utils

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('filename', type=str, help="filename")
parser.add_argument('users', type=str, nargs='+', help='users')
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p,
          proxy=args.proxy)

f = utils.file(args.filename)
for username in args.users:
    following = bot.get_user_following(username)
    f.save_list(following)
Beispiel #9
0
# -*- coding: utf-8 -*-

from glob import glob
import os
import threading
import time
import schedule
from instabot import Bot, utils
import config

bot = Bot(comments_file=config.COMMENTS_FILE, friends_file=config.FRIENDS_FILE)
bot.login()
bot.logger.info("Instagram bot. Safe to run 24/7!")

random_user_file = utils.file(config.USERS_FILE)
random_hashtag_file = utils.file(config.HASHTAGS_FILE)


def stats():
    bot.save_user_stats(bot.user_id)


def like_hashtags():
    bot.like_hashtag(random_hashtag_file.random(), amount=700 // 24)


def like_timeline():
    bot.like_timeline(amount=300 // 24)


def like_followers_from_random_user_file():
Beispiel #10
0
    follow_delay=130,
    unfollow_delay=130,
    comment_delay=60,
    block_delay=30,
    unblock_delay=30,
    message_delay=60,
    stop_words=(),
    verbosity=True,
)
bot.login(username="******", password="******")
bot.logger.info("ULTIMATE script. Safe to run 24/7!")

f = open("hashtag_database.txt", 'r')
hashtag_file_like_list = [f.read().split('\n')]

random_user_file = utils.file(config_file.USERS_FILE)
random_hashtag_file_like = utils.file(config_file.HASHTAGS_FILE_LIKE)
random_hashtag_file_follow = utils.file(config_file.HASHTAGS_FILE_FOLLOW)
photo_captions_file = utils.file(config_file.PHOTO_CAPTIONS_FILE)
posted_pic_list = utils.file(config_file.POSTED_PICS_FILE).list

pics = sorted(
    [os.path.basename(x) for x in glob(config_file.PICS_PATH + "/*.jpg")])


def stats():
    print("stats")
    #bot.save_user_stats(bot.user_id)


def like_hashtags():
Beispiel #11
0
parser.add_argument("-p", type=str, help="password")
parser.add_argument("-proxy", type=str, help="proxy")
parser.add_argument("-users",
                    type=str,
                    nargs="?",
                    help="a path to already notified users")
parser.add_argument("-message", type=str, nargs="?", help="message text")
args = parser.parse_args()
bot = Bot()
bot.login(username=args.u, password=args.p, proxy=args.proxy)
followers = bot.get_user_followers(args.u)
# Use custom message from args if exist
if args.message:
    MESSAGE = args.message
# Check on existed file with notified users
notified_users = utils.file(NOTIFIED_USERS_PATH)
if not notified_users.list:
    notified_users.save_list(followers)
    print("All followers saved in file {users_path}.\n"
          "In a next time, for all new followers script will send messages.".
          format(users_path=NOTIFIED_USERS_PATH))
    exit(0)
print("Read saved list of notified users. Count: {count}".format(
    count=len(notified_users)))
all_followers = followers
print("Amount of all followers is {count}".format(count=len(all_followers)))
new_followers = set(all_followers) - notified_users.set
if not new_followers:
    print("New followers not found")
    exit()
print("Found new followers. Count: {count}".format(count=len(new_followers)))
"""
    instabot example

    Workflow:
        1) unfollows users that don't follow you.
"""

import argparse
import os
import sys
from instabot import Bot, utils

sys.path.append(os.path.join(sys.path[0], "../"))
from instabot import Bot  # noqa: E402


parser = argparse.ArgumentParser(add_help=True)
parser.add_argument("-u", type=str, help="username")
parser.add_argument("-p", type=str, help="password")
parser.add_argument("-proxy", type=str, help="proxy")
args = parser.parse_args()

bot= Bot()
bot.logger.info("searching non archived documents")
non_archived = bot.toArchive.set - bot.archived.set
f = utils.file("non-archived.txt")
f.save_list(non_archived)
bot.logger.info("done")
"""
    instabot example

    Workflow:
        Save users' followers into a file.
"""
import os
import sys
import argparse

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot, utils

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('filename', type=str, help="filename")
parser.add_argument('users', type=str, nargs='+', help='users')
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p,
          proxy=args.proxy)

f = utils.file(args.filename)
for username in args.users:
    followers = bot.get_user_followers(username)
    f.save_list(followers)
Beispiel #14
0
def save_to_followed_today(user_id):
    followed_today_file = utils.file(followed_file_name(today()))
    followed_today_file.append(user_id)
    photo_path = bot.download_photo(new_media_id, save_description=True)
    if not photo_path or not isinstance(photo_path, str):
        # photo_path could be True, False, or a file path.
        return False
    with open(photo_path[:-3] + 'txt', 'r') as f:
        text = ''.join(f.readlines())
    if bot.upload_photo(photo_path, text):
        update_posted_medias(new_media_id, path)
        bot.logger.info('Media_id {0} is saved in {1}'.format(new_media_id, path))


parser = argparse.ArgumentParser(add_help=True)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('-file', type=str, help="users filename")
parser.add_argument('-amount', type=int, help="amount", default=1)
parser.add_argument('users', type=str, nargs='*', help='users')
args = parser.parse_args()

bot = Bot()
bot.login()

users = None
if args.users:
    users = args.users
elif args.file:
    users = utils.file(args.file).list

repost_best_photos(bot, users, args.amount)
Beispiel #16
0
    c = MyBot(bot)
    # c.refollow_friends()
    funcs = [
        # c.follow_and_like,
        c.unfollow_if_max_following,
        c.unfollow_after_time,
        c.unfollow_accepted_unreturned_requests,
        c.unfollow_failed_unfollows,
        # c.follow_random,
        # c.unfollow_followers_that_are_not_friends,
        # c.like_media_from_to_follow,
        # c.like_media_from_nonfollowers,
        # c.unfollow_all_non_friends,
    ]

    to_unfollow = utils.file("to_unfollow.txt")
    for u in to_unfollow.list:
        user_id = bot.get_user_id_from_username(u)
        c.unfollow(user_id)
        to_unfollow.remove(u)
        time.sleep(20)

    while True:
        n_per_day = 200
        n_seconds = 86400 / n_per_day
        t_start = time.time()
        if random.random() < n_seconds / (5 * 3600):
            # Invalidate the cache every ~5 hours
            c.bot._followers = None
        c.track_followers()
        random.shuffle(funcs)
Beispiel #17
0
          like_delay=1,
          follow_delay=5,
          unfollow_delay=5,
          max_followers_to_following_ratio=config.MAX,
          max_following_to_followers_ratio=config.MAX,
          base_path=config.BASE_PATH,
          blocked_actions_protection=False)

bot.login(username=os.environ["USERNAME"], password=os.environ["PASSWORD"])


def file_path(filename):
    return os.path.join(config.BASE_PATH, filename)


existing_followers = utils.file(config.EXISTING_FOLLOWERS_FILE)
processed_existing_followers = utils.file(
    file_path(config.PROCESSED_EXISTING_FOLLOWERS_FILE))
existing_followers_done = False


def all_users():
    return bot.read_list_from_file(config.USERS_FILE)


def random_user():
    return random.choice(all_users())


def followed_file_name(date):
    return file_path("followed_{}.txt".format(date.strftime("%Y%m%d")))
Beispiel #18
0
"""
import argparse
import os
import sys

sys.path.append(os.path.join(sys.path[0], "../"))
from instabot import Bot, utils  # noqa: E402

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-u", type=str, help="username")
parser.add_argument("-p", type=str, help="password")
parser.add_argument("-proxy", type=str, help="proxy")
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p, proxy=args.proxy)

f = utils.file("config/non-followers.txt")

non_followers = set(bot.following) - set(bot.followers) - bot.friends_file.set
non_followers = list(non_followers)
non_followers_names = []

for user in non_followers:
    name = bot.get_username_from_user_id(user)
    non_followers_names.append(name)
    print(name)
    bot.small_delay()

f.save_list(non_followers_names)
import time

sys.path.append(os.path.join(sys.path[0], '../../'))
import schedule
from instabot import Bot, utils

import config

bot = Bot(comments_file=config.COMMENTS_FILE,
          blacklist_file=config.BLACKLIST_FILE,
          whitelist_file=config.WHITELIST_FILE,
          friends_file=config.FRIENDS_FILE)
bot.login()
bot.logger.info("ULTIMATE script. Safe to run 24/7!")

random_user_file = utils.file(config.USERS_FILE)
random_hashtag_file = utils.file(config.HASHTAGS_FILE)
photo_captions_file = utils.file(config.PHOTO_CAPTIONS_FILE)
posted_pic_list = utils.file(config.POSTED_PICS_FILE).list

pics = sorted([os.path.basename(x) for x in
               glob(config.PICS_PATH + "/*.jpg")])


def stats():
    bot.save_user_stats(bot.user_id)


def like_hashtags():
    bot.like_hashtag(random_hashtag_file.random(), amount=700 // 24)
Beispiel #20
0
    def __init__(
            self,
            whitelist_file='whitelist.txt',
            blacklist_file='blacklist.txt',
            comments_file='comments.txt',
            followed_file='followed.txt',
            unfollowed_file='unfollowed.txt',
            skipped_file='skipped.txt',
            friends_file='friends.txt',
            proxy=None,
            max_likes_per_day=1000,
            max_unlikes_per_day=1000,
            max_follows_per_day=350,
            max_unfollows_per_day=350,
            max_comments_per_day=100,
            max_blocks_per_day=100,
            max_unblocks_per_day=100,
            max_likes_to_like=100,
            max_messages_per_day=300,
            filter_users=True,
            filter_business_accounts=True,
            filter_verified_accounts=True,
            max_followers_to_follow=20000000,
            min_followers_to_follow=5,
            max_following_to_follow=20000000,
            min_following_to_follow=5,
            max_followers_to_following_ratio=10,
            max_following_to_followers_ratio=2,
            min_media_count_to_follow=1,
            max_following_to_block=2000,
            like_delay=10,
            unlike_delay=10,
            follow_delay=30,
            unfollow_delay=30,
            comment_delay=60,
            block_delay=30,
            unblock_delay=30,
            message_delay=60,
            stop_words=('shop', 'store', 'free'),
            verbosity=True,
    ):
        self.api = API()

        self.total = {
            'likes': 0,
            'unlikes': 0,
            'follows': 0,
            'unfollows': 0,
            'comments': 0,
            'blocks': 0,
            'unblocks': 0,
            'messages': 0,
            'archived': 0,
            'unarchived': 0
        }

        self.start_time = datetime.datetime.now()

        self.delays = {
            'like': like_delay,
            'unlike': unlike_delay,
            'follow': follow_delay,
            'unfollow': unfollow_delay,
            'comment': comment_delay,
            'block': block_delay,
            'unblock': unblock_delay,
            'message': message_delay
        }

        self.last = {key: 0 for key in self.delays.keys()}

        # limits - follow
        self.filter_users = filter_users
        self.filter_business_accounts = filter_business_accounts
        self.filter_verified_accounts = filter_verified_accounts

        self.max_per_day = {
            'likes': max_likes_per_day,
            'unlikes': max_unlikes_per_day,
            'follows': max_follows_per_day,
            'unfollows': max_unfollows_per_day,
            'comments': max_comments_per_day,
            'blocks': max_blocks_per_day,
            'unblocks': max_unblocks_per_day,
            'messages': max_messages_per_day
        }

        self.max_likes_to_like = max_likes_to_like
        self.max_followers_to_follow = max_followers_to_follow
        self.min_followers_to_follow = min_followers_to_follow
        self.max_following_to_follow = max_following_to_follow
        self.min_following_to_follow = min_following_to_follow
        self.max_followers_to_following_ratio = max_followers_to_following_ratio
        self.max_following_to_followers_ratio = max_following_to_followers_ratio
        self.min_media_count_to_follow = min_media_count_to_follow
        self.stop_words = stop_words

        # limits - block
        self.max_following_to_block = max_following_to_block

        # current following and followers
        self._following = None
        self._followers = None
        self._user_infos = {}  # User info cache
        self._usernames = {}  # `username` to `user_id` mapping

        # Database files
        self.followed_file = utils.file(followed_file)
        self.unfollowed_file = utils.file(unfollowed_file)
        self.skipped_file = utils.file(skipped_file)
        self.friends_file = utils.file(friends_file)
        self.comments_file = utils.file(comments_file)
        self.blacklist_file = utils.file(blacklist_file)
        self.whitelist_file = utils.file(whitelist_file)

        self.proxy = proxy
        self.verbosity = verbosity

        self.logger = self.api.logger
        self.logger.info('Instabot Started')
"""
import os
import sys
import argparse

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot, utils

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p, proxy=args.proxy)

f = utils.file("non-followers.txt")

non_followers = set(bot.following) - set(bot.followers) - bot.friends_file.set
non_followers = list(non_followers)
non_followers_names = []

for user in non_followers:
    name = bot.get_username_from_user_id(user)
    non_followers_names.append(name)
    print(name)
    bot.small_delay()

f.save_list(non_followers_names)
Beispiel #22
0
        Save users' followers into a file.
"""
import os
import sys
import argparse

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot, utils

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('users', type=str, nargs='+', help='users')
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p,
          proxy=args.proxy)
followerAndMedia = []
f = utils.file("usersToFollow.txt")
for username in args.users:
    followers = bot.get_user_followers(username, 7000)
    for follower in followers:
        media = []
        sum_media = ""
        media = bot.get_last_user_medias(follower, 3)
        sum_media = ':'.join(str(m) for m in media)
        followerAndMedia.append(follower + ":" + sum_media)
    f.save_list(followerAndMedia)
Beispiel #23
0
def followed_3_days_ago():
    filename = followed_file_name(three_days_ago())
    return utils.file(filename).list
def exists_in_posted_medias(new_media_id, path=POSTED_MEDIAS):
    medias = utils.file(path).list
    return str(new_media_id) in medias
Beispiel #25
0
def add_whitelist():
    f = utils.file(whitelist_file)
    following = bot.get_user_following(username)
    f.save_list(following)
Beispiel #26
0
    def __init__(
        self,
        base_path=current_path + "/config/",
        whitelist_file="whitelist.txt",
        blacklist_file="blacklist.txt",
        comments_file="comments.txt",
        followed_file="followed.txt",
        unfollowed_file="unfollowed.txt",
        skipped_file="skipped.txt",
        friends_file="friends.txt",
        proxy=None,
        max_likes_per_day=random.randint(50, 100),
        max_unlikes_per_day=random.randint(50, 100),
        max_follows_per_day=random.randint(50, 100),
        max_unfollows_per_day=random.randint(50, 100),
        max_comments_per_day=random.randint(50, 100),
        max_blocks_per_day=random.randint(50, 100),
        max_unblocks_per_day=random.randint(50, 100),
        max_likes_to_like=random.randint(50, 100),
        min_likes_to_like=random.randint(50, 100),
        max_messages_per_day=random.randint(50, 100),
        filter_users=False,
        filter_private_users=False,
        filter_users_without_profile_photo=False,
        filter_previously_followed=False,
        filter_business_accounts=False,
        filter_verified_accounts=False,
        max_followers_to_follow=5000,
        min_followers_to_follow=10,
        max_following_to_follow=2000,
        min_following_to_follow=10,
        max_followers_to_following_ratio=15,
        max_following_to_followers_ratio=15,
        min_media_count_to_follow=3,
        max_following_to_block=2000,
        like_delay=random.randint(300, 600),
        unlike_delay=random.randint(300, 600),
        follow_delay=random.randint(300, 600),
        unfollow_delay=random.randint(300, 600),
        comment_delay=random.randint(300, 600),
        block_delay=random.randint(300, 600),
        unblock_delay=random.randint(300, 600),
        message_delay=random.randint(300, 600),
        stop_words=("shop", "store", "free"),
        blacklist_hashtags=["#shop", "#store", "#free"],
        blocked_actions_protection=True,
        blocked_actions_sleep=True,
        blocked_actions_sleep_delay=random.randint(600, 1200),
        verbosity=True,
        device=None,
        save_logfile=True,
        log_filename=None,
        loglevel_file=logging.DEBUG,
        loglevel_stream=logging.INFO,
        log_follow_unfollow=True,
    ):
        self.api = API(
            device=device,
            base_path=base_path,
            save_logfile=save_logfile,
            log_filename=log_filename,
            loglevel_file=loglevel_file,
            loglevel_stream=loglevel_stream,
        )
        self.log_follow_unfollow = log_follow_unfollow
        self.base_path = base_path

        self.state = BotState()

        self.delays = {
            "like": like_delay,
            "unlike": unlike_delay,
            "follow": follow_delay,
            "unfollow": unfollow_delay,
            "comment": comment_delay,
            "block": block_delay,
            "unblock": unblock_delay,
            "message": message_delay,
        }

        # limits - follow
        self.filter_users = filter_users
        self.filter_private_users = filter_private_users
        self.filter_users_without_profile_photo = filter_users_without_profile_photo
        self.filter_business_accounts = filter_business_accounts
        self.filter_verified_accounts = filter_verified_accounts
        self.filter_previously_followed = filter_previously_followed

        self.max_per_day = {
            "likes": max_likes_per_day,
            "unlikes": max_unlikes_per_day,
            "follows": max_follows_per_day,
            "unfollows": max_unfollows_per_day,
            "comments": max_comments_per_day,
            "blocks": max_blocks_per_day,
            "unblocks": max_unblocks_per_day,
            "messages": max_messages_per_day,
        }

        self.blocked_actions_protection = blocked_actions_protection

        self.blocked_actions_sleep = blocked_actions_sleep
        self.blocked_actions_sleep_delay = blocked_actions_sleep_delay

        self.max_likes_to_like = max_likes_to_like
        self.min_likes_to_like = min_likes_to_like
        self.max_followers_to_follow = max_followers_to_follow
        self.min_followers_to_follow = min_followers_to_follow
        self.max_following_to_follow = max_following_to_follow
        self.min_following_to_follow = min_following_to_follow
        self.max_followers_to_following_ratio = max_followers_to_following_ratio
        self.max_following_to_followers_ratio = max_following_to_followers_ratio
        self.min_media_count_to_follow = min_media_count_to_follow
        self.stop_words = stop_words
        self.blacklist_hashtags = blacklist_hashtags

        # limits - block
        self.max_following_to_block = max_following_to_block

        # current following and followers
        self.cache = BotCache()

        # Adjust file paths
        followed_file = os.path.join(base_path, followed_file)
        unfollowed_file = os.path.join(base_path, unfollowed_file)
        skipped_file = os.path.join(base_path, skipped_file)
        friends_file = os.path.join(base_path, friends_file)
        comments_file = os.path.join(base_path, comments_file)
        blacklist_file = os.path.join(base_path, blacklist_file)
        whitelist_file = os.path.join(base_path, whitelist_file)

        # Database files
        self.followed_file = utils.file(followed_file)
        self.unfollowed_file = utils.file(unfollowed_file)
        self.skipped_file = utils.file(skipped_file)
        self.friends_file = utils.file(friends_file)
        self.comments_file = utils.file(comments_file)
        self.blacklist_file = utils.file(blacklist_file)
        self.whitelist_file = utils.file(whitelist_file)

        self.proxy = proxy
        self.verbosity = verbosity

        self.logger = self.api.logger
        self.logger.info("Instabot version: " + version + " Started")
        self.logger.debug("Bot imported from {}".format(__file__))
Beispiel #27
0
        Save users' followers into a file.
"""
import os
import sys
import argparse

sys.path.append(os.path.join(sys.path[0], '../'))
from instabot import Bot, utils

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('-u', type=str, help="username")
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('users', type=str, nargs='+', help='users')
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p, proxy=args.proxy)
myFollowers = []
myFollowing = []
foler = utils.file("myFollowers.txt")
foling = utils.file("myFollowing.txt")
for username in args.users:
    followers = bot.get_user_followers(username, 9000)
    for follower in followers:
        myFollowers.append(follower)
    foler.save_list(myFollowers)
    #followings = bot.get_user_following(username, 100000)
    #for following in followings:
    #    myFollowing.append(following)
    #foling.save_list(myFollowing)
parser.add_argument('-p', type=str, help="password")
parser.add_argument('-proxy', type=str, help="proxy")
parser.add_argument('-users', type=str, nargs='?', help='a path to already notified users')
parser.add_argument('-message', type=str, nargs='?', help='message text')
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p,
          proxy=args.proxy)

# Use custom message from args if exist
if args.message:
    MESSAGE = args.message

# Check on existed file with notified users
notified_users = utils.file(NOTIFIED_USERS_PATH)
if not notified_users.list:
    notified_users.save_list(bot.followers)
    print(
        'All followers saved in file {users_path}.\n'
        'In a next time, for all new followers script will send messages.'.format(
            users_path=NOTIFIED_USERS_PATH
        )
    )
    exit(0)

print('Read saved list of notified users. Count: {count}'.format(
    count=len(notified_users)
))
all_followers = bot.followers
print('Amount of all followers is {count}'.format(
def update_posted_medias(new_media_id, path=POSTED_MEDIAS):
    medias = utils.file(path)
    medias.append(str(new_media_id))
    return True
import os
import sys

sys.path.append(os.path.join(sys.path[0], "../"))
from instabot import Bot, utils  # noqa: E402

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("-u", type=str, help="username")
parser.add_argument("-p", type=str, help="password")
parser.add_argument("-proxy", type=str, help="proxy")
args = parser.parse_args()

bot = Bot()
bot.login(username=args.u, password=args.p, proxy=args.proxy)

f = utils.file("non-followers.txt")
f2 = utils.file("whitelist-id.txt")
whitelisters = []
for user in list(bot.whitelist_file.set):
    bot.small_delay()
    user_id = bot.convert_to_user_id(user)
    whitelisters.append(user_id)
f2.save_list(whitelisters)

non_followers = list(bot.following_file.set - bot.whitelist_file.set -
                     bot.friends_file.set - bot.followers_file.set)
non_followers_names = []

for user in non_followers:
    name = bot.get_username_from_user_id(user)
    non_followers_names.append(name)
Beispiel #31
0
    proxy_file = open(config.PROXY_FILE, "r")
    if proxy_file:
        working_proxy = proxy_file.readline()
        if working_proxy and re.match(working_proxy, "https://*:*"):
            proxy = working_proxy

function = args.f
bot = Bot(comments_file=config.COMMENTS_FILE,
          blacklist_file=config.BLACKLIST_FILE,
          whitelist_file=config.WHITELIST_FILE,
          friends_file=config.FRIENDS_FILE,
          proxy=proxy)
bot.login(username="******")
bot.logger.info("ULTIMATE script. Safe to run 24/7!")

random_user_file = utils.file(config.USERS_FILE)
random_hashtag_file = utils.file(config.HASHTAGS_FILE)
photo_captions_file = utils.file(config.PHOTO_CAPTIONS_FILE)
posted_pic_list = utils.file(config.POSTED_PICS_FILE).list

pics = sorted([os.path.basename(x) for x in glob(config.PICS_PATH + "/*.jpg")])


def stats():
    bot.save_user_stats(bot.user_id)


def like_hashtags():
    bot.like_hashtag(random_hashtag_file.random(), amount=700 // 24)

Beispiel #32
0
from instabot import Bot, utils  # noqa: E402

#cool

bot = Bot(
    comments_file=config.COMMENTS_FILE,
    blacklist_file=config.BLACKLIST_FILE,
    whitelist_file=config.WHITELIST_FILE,
    friends_file=config.FRIENDS_FILE,
)

bot.login(username="******",password="******")

bot.logger.info("ULTIMATE script. Safe to run 24/7!")

random_user_file = utils.file(config.USERS_FILE)
random_hashtag_file = utils.file(config.HASHTAGS_FILE)
photo_captions_file = utils.file(config.PHOTO_CAPTIONS_FILE)


def stats():
    bot.save_user_stats(bot.user_id)


def like_hashtags():
    bot.like_hashtag(random_hashtag_file.random(), amount=700 // 24)


def like_timeline():
    bot.like_timeline(amount=300 // 24)