def test_login(self): self.bot = Bot() def mockreturn(*args, **kwargs): r = Mock() r.status_code = 200 r.text = '{"status": "ok"}' return r def mockreturn_login(*args, **kwargs): r = Mock() r.status_code = 200 r.text = json.dumps({ "logged_in_user": { "pk": self.USER_ID, "username": self.USERNAME, "full_name": self.FULLNAME }, "status": "ok" }) return r with patch('requests.Session') as Session: instance = Session.return_value instance.get.return_value = mockreturn() instance.post.return_value = mockreturn_login() instance.cookies = requests.cookies.RequestsCookieJar() instance.cookies.update( {'csrftoken': self.TOKEN, 'ds_user_id': self.USER_ID}) assert self.bot.api.login(username=self.USERNAME, password=self.PASSWORD) assert self.bot.api.username == self.USERNAME assert self.bot.user_id == self.USER_ID assert self.bot.api.is_logged_in assert self.bot.api.uuid assert self.bot.api.token
Workflow: Block bots. That makes them unfollow you -> You have clear account. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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() stop_words = ['shop', 'store', 'free'] bot = Bot(stop_words=stop_words) bot.login(username=args.u, password=args.p, proxy=args.proxy) bot.logger.info("This script will block bots. " "So they will no longer be your follower. " "Bots are those users who:\n" " * follow more than (sample value - change in file) 2000 users\n" " * have stopwords in user's info: " " %s " % str(stop_words)) bot.block_bots()
""" instabot example Workflow: Follow user's followers by username. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('users', type=str, nargs='+', help='users') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: bot.follow_followers(username)
""" instabot example Workflow: Download the specified user's medias """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot parser = argparse.ArgumentParser(add_help=True) parser.add_argument('username', type=str, help='@username') args = parser.parse_args() if args.username[0] != "@": # if first character isn't "@" args.username = "******" + args.username bot = Bot() bot.login() medias = bot.get_total_user_medias(args.username) bot.download_photos(medias)
from io import open sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot posted_pic_list = [] try: with open('pics.txt', 'r', encoding='utf8') as f: posted_pic_list = f.read().splitlines() except Exception: posted_pic_list = [] timeout = 24 * 60 * 60 # pics will be posted every 24 hours bot = Bot() bot.login() while True: pics = glob.glob("./pics/*.jpg") pics = sorted(pics) try: for pic in pics: if pic in posted_pic_list: continue caption = pic[:-4].split(" ") caption = " ".join(caption[1:]) print("upload: " + caption) bot.upload_photo(pic, caption=caption)
This script take my likers who don't follow me and like them. """ import os import time import random from instabot import Bot def like_media_likers(bot, media, nlikes=2): for user in bot.get_media_likers(media): bot.like_user(user, nlikes) return True bot = Bot() bot.login( username=os.getenv("INSTAGRAM_USERNAME"), password=os.getenv("INSTAGRAM_PASSWORD"), ) my_last_medias = bot.get_your_medias() my_likers = set([ liker for media in my_last_medias for liker in bot.get_media_likers(media) ]) print("Found %d likers" % len(my_likers)) my_followers = set(bot.followers) likers_that_dont_follow = my_likers - my_followers
""" instabot example Collects the information about your account every hour in username.tsv file. """ import os import sys import time sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot if len(sys.argv) != 2: print("USAGE: Pass username to collect stats of - saved in username.tsv (same dir).") print("Example: python %s account1" % sys.argv[0]) exit() delay = 60 * 60 # in seconds bot = Bot() bot.login() while True: bot.save_user_stats(sys.argv[1]) time.sleep(delay)
import argparse import os import sys import time from random import shuffle sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) like_hashtags_list = bot.read_list_from_file("like_hashtags.txt") all_users = [] for hashtag in like_hashtags_list: users = bot.get_hashtag_users(hashtag) all_users += users #randomization routine shuffle(all_users) bot.follow_users(users) time.sleep(10)
""" instabot example Workflow: 1) unfollows every from your account. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) bot.unfollow_everyone()
""" instabot example Workflow: Like user's, follower's media by user_id. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('users', type=str, nargs='+', help='users') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: bot.like_followers(username, nlikes=3)
Workflow: 1) likes your timeline feed 2) likes user's feed Notes: 1) You should pass user_id, not username """ import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot bot = Bot() bot.login() # like media by a single user_id bot.like_user("352300017") # likes all media from timeline bot.like_timeline() # likes all media from timeline bot.like_medias(bot.get_timeline_medias()) # likes media by hashtag(s) tags = ["l4l", "selfie"] for t in tags:
""" instabot example Workflow: 1) unfollows users that don't follow you. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) bot.unfollow_non_followers()
It uses data written in files: * follow_followers.txt * follow_following.txt * like_hashtags.txt * like_users.txt and do the job. This bot can be run 24/7. """ import os import sys sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot bot = Bot() bot.login() print("Current script's schedule:") follow_followers_list = bot.read_list_from_file("follow_followers.txt") print("Going to follow followers of:", follow_followers_list) follow_following_list = bot.read_list_from_file("follow_following.txt") print("Going to follow following of:", follow_following_list) like_hashtags_list = bot.read_list_from_file("like_hashtags.txt") print("Going to like hashtags:", like_hashtags_list) like_users_list = bot.read_list_from_file("like_users.txt") print("Going to like users:", like_users_list) tasks_list = [] for item in follow_followers_list: tasks_list.append((bot.follow_followers, {'user_id': item, 'nfollows': None}))
The file should have one comment per line. Workflow: 1) Get your timeline medias 2) Comment them with random comments from file. Notes: You can change file and add there your comments. """ import sys import os sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot if len(sys.argv) != 2: print("USAGE: Pass a path to the file with comments") print("Example: %s comments_emoji.txt" % sys.argv[0]) exit() comments_file_name = sys.argv[1] if not os.path.exists(comments_file_name): print("Can't find '%s' file." % comments_file_name) exit() bot = Bot(comments_file=comments_file_name) bot.login() bot.comment_medias(bot.get_timeline_medias()) bot.logout()
Workflow: Follow users who post medias with hashtag. """ import argparse import os import sys import time sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('hashtags', type=str, nargs='+', help='hashtags') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) wait = 5 * 60 # in seconds while True: for hashtag in args.hashtags: users = bot.get_hashtag_users(hashtag) bot.follow_users(users) time.sleep(wait)
class TestBotAPI(TestBot): def test_login(self): self.bot = Bot() def mockreturn(*args, **kwargs): r = Mock() r.status_code = 200 r.text = '{"status": "ok"}' return r def mockreturn_login(*args, **kwargs): r = Mock() r.status_code = 200 r.text = json.dumps({ "logged_in_user": { "pk": self.USER_ID, "username": self.USERNAME, "full_name": self.FULLNAME }, "status": "ok" }) return r with patch('requests.Session') as Session: instance = Session.return_value instance.get.return_value = mockreturn() instance.post.return_value = mockreturn_login() instance.cookies = requests.cookies.RequestsCookieJar() instance.cookies.update( {'csrftoken': self.TOKEN, 'ds_user_id': self.USER_ID}) assert self.bot.api.login(username=self.USERNAME, password=self.PASSWORD) assert self.bot.api.username == self.USERNAME assert self.bot.user_id == self.USER_ID assert self.bot.api.is_logged_in assert self.bot.api.uuid assert self.bot.api.token def test_generate_uuid(self): from uuid import UUID generated_uuid = self.bot.api.generate_UUID(True) assert isinstance(UUID(generated_uuid), UUID) assert UUID(generated_uuid).hex == generated_uuid.replace('-', '') def test_set_user(self): test_username = "******" test_password = "******" self.bot.api.set_user(test_username, test_password) assert self.bot.api.username == test_username assert self.bot.api.password == test_password assert hasattr(self.bot.api, "uuid") def test_reset_counters(self): keys = ['liked', 'unliked', 'followed', 'messages', 'unfollowed', 'commented', 'blocked', 'unblocked'] for key in keys: self.bot.total[key] = 1 assert self.bot.total[key] == 1 self.bot.reset_counters() for key in keys: assert self.bot.total[key] == 0
from instabot import Bot bot = Bot() bot.login(username="******", password="******") bot.upload_photo("img.jpg", caption="uploaded by bot")
""" 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)
from instabot import Bot bot = Bot() bot.login(username="******", password="******")
Workflow: Take users from input file and follow them. The file should contain one username per line! """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('filepath', type=str, help='filepath') args = parser.parse_args() bot = Bot(filter_users=False) users_to_follow = bot.read_list_from_file(args.filepath) if not users_to_follow: exit() else: print("Found %d users in file." % len(users_to_follow)) bot.login(username=args.u, password=args.p, proxy=args.proxy) bot.follow_users(users_to_follow)
""" instabot example Workflow: 1) unfollows users that have followers < following. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) bot.unfollow_usersWithLessFollowers()
""" instabot example Workflow: 1) Downloads your medias """ import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot bot = Bot() bot.login() medias = bot.get_total_user_medias(bot.user_id) bot.download_photos(medias)
Workflow: Follow users who liked the last media of input users. """ import argparse import os import sys from tqdm import tqdm sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('users', type=str, nargs='+', help='users') args = parser.parse_args() bot = Bot(max_follows_per_day=25, follow_delay=30) bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: medias = bot.get_user_medias(username, filtration=False) if medias: likers = bot.get_media_likers(medias[0]) for liker in tqdm(likers): bot.follow(liker)
blacklist and whitelist files should contain user_ids - each one on the separate line. Example: 1234125 1234124512 """ import sys import os from tqdm import tqdm import argparse sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot 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(whitelist_file="whitelist.txt", blacklist_file="blacklist.txt") bot.login(username=args.u, password=args.p, proxy=args.proxy) timeline_medias = bot.get_timeline_medias() for media in tqdm(timeline_medias, desc="timeline"): bot.like_user(bot.get_media_owner(media))
def like_and_follow(bot, user_id, nlikes=3): bot.like_user(user_id, amount=nlikes) bot.follow(user_id) return True def like_and_follow_media_likers(bot, media, nlikes=3): for user in tqdm(bot.get_media_likers(media), desc="Media likers"): like_and_follow(bot, user, nlikes) time.sleep(10 + 20 * random.random()) return True def like_and_follow_your_feed_likers(bot, nlikes=3): last_media = bot.get_your_medias()[0] return like_and_follow_media_likers(bot, last_media, nlikes=nlikes) 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.login(username=args.u, password=args.p, proxy=args.proxy) like_and_follow_your_feed_likers(bot)
sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot, utils NOTIFIED_USERS_PATH = 'notified_users.txt' MESSAGE = 'Thank you for a script, sudoguy!' 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('-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
""" instabot example Workflow: 1) Unarchives your last medias """ import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot bot = Bot() bot.login() medias = bot.get_archived_medias() bot.unarchive_medias(medias)
""" instabot example Workflow: Like last medias by users. """ import sys import os import time import random from tqdm import tqdm import argparse sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('users', type=str, nargs='+', help='users') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: bot.like_user(username)
bot = Bot( max_likes_per_day=setting_0, max_unlikes_per_day=setting_1, max_follows_per_day=setting_2, max_unfollows_per_day=setting_3, max_comments_per_day=setting_4, max_likes_to_like=setting_5, max_followers_to_follow=setting_6, min_followers_to_follow=setting_7, max_following_to_follow=setting_8, min_following_to_follow=setting_9, max_followers_to_following_ratio=setting_10, max_following_to_followers_ratio=setting_11, min_media_count_to_follow=setting_12, like_delay=setting_13, unlike_delay=setting_14, follow_delay=setting_15, unfollow_delay=setting_16, comment_delay=setting_17, whitelist_file=whitelist, blacklist_file=blacklist, comments_file=comment, stop_words=[ 'order', 'shop', 'store', 'free', 'doodleartindonesia', 'doodle art indonesia', 'fullofdoodleart', 'commission', 'vector', 'karikatur', 'jasa', 'open'])
import os import sys import time import datetime import json from random import shuffle # ------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------ sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot bot = Bot() #TXT File Path /// filePath = os.path.dirname(os.path.abspath(__file__)) + "/" bot.login(username="******", password="******") MAX_RETRIES = 100 session = requests.Session() adapter = requests.adapters.HTTPAdapter(max_retries=MAX_RETRIES) session.mount('https://', adapter) session.mount('http://', adapter) def check_if_folder_exists(directory_name):
from instabot import Bot from time import sleep from random import randint import authentication bot = Bot() bot.login(username=authentication.USERNAME, password=authentication.PASSWORD) following = (bot.following) followers = (bot.followers) for i in following: if i in followers: continue else: print((bot.get_user_info(i))['username']) # If you want to unfollow them too, uncomment the bellow two lines as well. #bot.unfollow(i) #sleep(randint(6,12))
""" import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) print("Current script's schedule:") follow_followers_list = bot.read_list_from_file("follow_followers.txt") print("Going to follow followers of:", follow_followers_list) follow_following_list = bot.read_list_from_file("follow_following.txt") print("Going to follow following of:", follow_following_list) like_hashtags_list = bot.read_list_from_file("like_hashtags.txt") print("Going to like hashtags:", like_hashtags_list) like_users_list = bot.read_list_from_file("like_users.txt") print("Going to like users:", like_users_list)
args = parser.parse_args() try: print(u'Like medias by location') except TypeError: sys.stdout = stdout bot = Bot(max_likes_per_day=800, max_unlikes_per_day=0, max_follows_per_day=200, filter_users=True, max_followers_to_follow=5000, min_followers_to_follow=200, max_following_to_follow=99999999, min_following_to_follow=600, max_followers_to_following_ratio=0.4, max_following_to_followers_ratio=100000, max_following_to_block=99999999, min_media_count_to_follow=1, follow_delay=60, like_delay=25, whitelist=False, blacklist=False, comments_file=False) bot.login(username=args.u, password=args.p, proxy=args.proxy) if args.locations: for location in args.locations: print(u"Location: {}".format(location)) bot.searchLocation(location) finded_location = bot.LastJson['items'][0]
parser.add_argument('-proxy', type=str, help="proxy") args = parser.parse_args() def choice(message): get_choice = input(message) if get_choice == 'y': return True elif get_choice == 'n': return False else: print("Invalid Input") return choice(message) bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) if bot.api.getv2Inbox(): data = bot.last_json['inbox']['threads'] for item in data: bot.console_print(item['inviter']['username'], 'lightgreen') user_id = str(item['inviter']['pk']) last_item = item['last_permanent_item'] item_type = last_item['item_type'] if item_type == 'text': print(last_item['text']) if choice('Do you want to reply to this message?(y/n)'): text = input('write you message: ') if choice('send message?(y/n)'): bot.send_message(text,
def create_bot(): login = os.getenv('INST_LOGIN') password = os.getenv('INST_PSWRD') bot = Bot() bot.login(username=login, password=password) return bot
""" instabot example Workflow: Like last medias by user. """ import sys import os import time import random from tqdm import tqdm sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot if len(sys.argv) < 2: print("USAGE: Pass username / usernames to like.") print("Example: python %s ohld lenakolenka" % sys.argv[0]) exit() bot = Bot() bot.login() for username in sys.argv[1:]: bot.like_user(username)
import os, time, random from dotenv import load_dotenv from instabot import Bot if __name__ == "__main__": load_dotenv() bot = Bot() bot.login(username=os.getenv('INSTAGRAM_LOGIN'), password=os.getenv('INSTAGRAM_PASSWORD')) folder = 'images' for filename in os.listdir(folder): bot.upload_photo(os.path.join(folder, filename)) time.sleep(random.randrange(15, 35))
from instabot import Bot bot = Bot() bot.login() bot.like_timeline() bot.like_user("352300017") bot.follow_users(["352300017"])
sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot bot = Bot(comments_file="comments.txt", blacklist="blacklist.txt", proxy=None, max_likes_per_day=300, max_unlikes_per_day=1000, max_follows_per_day=75, max_unfollows_per_day=80, max_comments_per_day=100, max_likes_to_like=100, filter_users=True, max_followers_to_follow=2000, min_followers_to_follow=40, max_following_to_follow=7500, min_following_to_follow=150, max_followers_to_following_ratio=0.9, max_following_to_followers_ratio=99999999, max_following_to_block=99999999, min_media_count_to_follow=3, like_delay=30, unlike_delay=30, follow_delay=60, unfollow_delay=150, comment_delay=120, whitelist=False, stop_words=['shop', 'store', 'free']) bot.login() bot.logger.info("ULTIMATE script. 24hours save")
def load_img_insta(user_name, pass_word): imgs = os.listdir('image2') bot = Bot() bot.login(username=user_name, password=pass_word) for img in imgs: bot.upload_photo(f'image2/{img}')
bot = Bot( max_likes_per_day=setting_0, max_unlikes_per_day=setting_1, max_follows_per_day=setting_2, max_unfollows_per_day=setting_3, max_comments_per_day=setting_4, max_likes_to_like=setting_5, max_followers_to_follow=setting_6, min_followers_to_follow=setting_7, max_following_to_follow=setting_8, min_following_to_follow=setting_9, max_followers_to_following_ratio=setting_10, max_following_to_followers_ratio=setting_11, min_media_count_to_follow=setting_12, like_delay=setting_13, unlike_delay=setting_14, follow_delay=setting_15, unfollow_delay=setting_16, comment_delay=setting_17, whitelist=whitelist, blacklist=blacklist, comments_file=comment, stop_words=[ 'order', 'shop', 'store', 'free', 'doodleartindonesia', 'doodle art indonesia', 'fullofdoodleart', 'commission', 'vector', 'karikatur', 'jasa', 'open'])
import captions_for_medias 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") parser.add_argument("-photo", type=str, help="photo name") parser.add_argument("-caption", type=str, help="caption for photo") parser.add_argument('-tag', action='append', help='taged user id') args = parser.parse_args() bot = Bot() bot.login() posted_pic_file = "pics.txt" posted_pic_list = [] caption = "" if not os.path.isfile(posted_pic_file): with open(posted_pic_file, "w"): pass else: with open(posted_pic_file, "r") as f: posted_pic_list = f.read().splitlines() # Get the filenames of the photos in the path ->
""" instabot example Workflow: 1) unfollows every from your account. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot # 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.login(username=args.u, password=args.p, # proxy=args.proxy) bot = Bot() bot.login(username="******", password="******") bot.unfollow_everyone()
def start(): print("Bot starting Beep Boop") current_hot = [] post_history = [] reddit = praw.Reddit(client_id='REDDIT-BOT-ID', client_secret='REDDIT-BOT-SECRET', user_agent='INSTAGRAM-BOT-NAME', username='******', password='******') subreddit = list(reddit.subreddit('blackpeopletwitter').hot(limit=12)) for submissions in subreddit[2:]: current_hot.append( (submissions.url, submissions.title, submissions.shortlink)) bot = Bot() bot.login(username="******", password="******") while True: print("trying to find new content beep boop") compare_List = [] subreddit = list(reddit.subreddit('blackpeopletwitter').hot(limit=12)) for submissions in subreddit[2:]: compare_List.append( (submissions.url, submissions.title, submissions.shortlink)) print([i for i in compare_List if i not in current_hot]) if set(compare_List) != set(current_hot): print("New post detected") temp = ([i for i in compare_List if i not in current_hot]) print(temp) current_hot = compare_List for tuples in temp: if tuples[0] not in post_history: urllib.request.urlretrieve(tuples[0], "temp.jpg") print("Picture is being posted -- beep boop") tweet_string = tweet_analysis.tweet_text("temp.jpg") try: if tweet_string != 'imgur format': bot.upload_photo("temp.jpg", caption=tuples[1] + " #reddit #blackpeopletwitter " + tweet_string) else: print("imgur format not uploadable yet") continue except RuntimeError: print("error caught!") continue post_history.append(tuples[0]) print("sucess!") now = datetime.now() current_time = now.strftime("%H:%M:%S") print("Trying again in 10 Min, current Time =", current_time) print(post_history) time.sleep(600)
log.info("Wait 2200 - 2600 sec for next repost") time.sleep(randint(2200, 2800)) except: log.info("image set to private " + scraped_user) x += 1 time.sleep(randint(5, 20)) instascraper(bot, new_media_id, path=POSTED_MEDIAS) x += 1 x = 0 time.sleep(randint(10, 30)) instascraper(bot, new_media_id, path=POSTED_MEDIAS) # All main stuff gets executed open_profiles() time.sleep(randint(5, 30)) bot = Bot() #bot.login(username=InstaUsername) bot.login(username=args.u, password=args.p) time.sleep(randint(10, 30)) user_id = bot.get_user_id_from_username(args.u) username = bot.get_username_from_user_id(user_id) #print(f"Welcome {username} your userid is {user_id}") saveStats = bot.save_user_stats(username) users = None if args.users: users = args.users elif args.file: users = utils.file(args.file).list instascraper(bot, users, args.amount)
import os import sys from instabot import Bot bot = Bot(filter_users=True) users_to_follow = bot.read_list_from_file('followers.txt') if not users_to_follow: exit() else: print("Found %d users in file." % len(users_to_follow)) bot.login(username=str(sys.argv[1]), password=str(sys.argv[2])) bot.follow_users(users_to_follow)
Workflow: Like last images with hashtag. """ import argparse import os import sys import time sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('hashtags', type=str, nargs='+', help='hashtags') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) wait = 5 * 60 # in seconds while True: for hashtag in args.hashtags: bot.like_hashtag(hashtag) time.sleep(wait)
@author: Kianoush GitHUb:https://github.com/Kianoush-h YouTube: https://www.youtube.com/channel/UCvf9_53f6n3YjNEA4NxAkJA?view_as=subscriber LinkedIn: https://www.linkedin.com/in/kianoush-haratiannejadi/ Email: [email protected] """ from instabot import Bot username_ = 'kia_python' password_ = 'KIA_python@' bot = Bot() bot.login(username=username_, password=password_) tag_list = ['python', 'programmer', 'Kinaoush'], for i in tag_list: bot.like_hashtag(i) users = ['python', 'python.learning', 'codder', 'kinaoush'] bot.follow_users(user_ids='python.learning') locs = ['Montreal', 'Canada', 'US', 'Iran'] for i in locs: bot.like_location_feed(i, amount=10)
""" instabot example Workflow: delete all posts in profile. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) medias = bot.get_total_user_medias(bot.user_id) bot.delete_medias(medias)
""" instabot example Workflow: Follow user's followers by username. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot parser = argparse.ArgumentParser(add_help=True) parser.add_argument('-u', type=str, help="aurimblys") parser.add_argument('-p', type=str, help="adrenalinasjiega1") parser.add_argument('-proxy', type=str, help="proxy") parser.add_argument('users', type=str, nargs='+', help='maybach420') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: bot.follow_followers(username)
""" instabot example Workflow: Like rescent medias from your timeline feed. """ import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot bot = Bot() bot.login() bot.like_timeline()
def bot_instantiate(user_name, user_password): # Initialize bot = Bot() bot.login(username=user_name, password=user_password) return bot
""" instabot example Workflow: Like rescent medias from your timeline feed. """ import argparse import os import sys import time sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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.login(username=args.u, password=args.p, proxy=args.proxy) wait = 5 * 60 # in seconds while True: bot.like_timeline() time.sleep(wait)
def post_image(username, password, image_file): bot = Bot() bot.login(username=username, password=password) bot.upload_photo(f"images/{image_file}")
Collects the information about your account every hour in username.tsv file. """ import argparse import os import sys import time sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('user', type=str, nargs='*', help="user") parser.add_argument('-path', type=str, default='', help="path") args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) delay = 60 * 60 while True: bot.save_user_stats(args.user, path=args.path) time.sleep(delay)
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]
""" instabot example Workflow: Download media photos with hashtag. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('hashtags', type=str, nargs='+', help='hashtags') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for hashtag in args.hashtags: medias = bot.get_hashtag_medias(hashtag) bot.download_photos(medias)
file.writelines('\n'.join(medias)) return True def repost_photo(bot, new_media_id, path='posted_medias.txt'): if exists_in_posted_medias(new_media_id, path): bot.logger.warning( "Media {0} was uploaded earlier".format(new_media_id)) return False photo_path = bot.download_photo(new_media_id, save_description=True) if not photo_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)) media_id = '' if not media_id: print('Media id is empty!') exit(1) bot = Bot() bot.login() repost_photo(bot, media_id)
""" instabot example Workflow: Like last medias by users. """ import argparse import os import sys sys.path.append(os.path.join(sys.path[0], '../')) from instabot import Bot 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('users', type=str, nargs='+', help='users') args = parser.parse_args() bot = Bot() bot.login(username=args.u, password=args.p, proxy=args.proxy) for username in args.users: bot.like_user(username, filtration=False)
Dependencies: You must have a file with comments to post. The file should have one comment per line. Notes: You can change file and add there your comments. """ import sys import os sys.path.append(os.path.join(sys.path[0], '../../')) from instabot import Bot if len(sys.argv) < 3: print("USAGE: Pass a path to the file with comments and an hastag to comment") print("Example: %s comments_emoji.txt dog cat" % sys.argv[0]) exit() comments_file_name = sys.argv[1] hashtags = sys.argv[2:] if not os.path.exists(comments_file_name): print("Can't find '%s' file." % comments_file_name) exit() bot = Bot(comments_file=comments_file_name) bot.login() for hashtag in hashtags: bot.comment_hashtag(hashtag) bot.logout()