Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- instabot example
- Collects the information about your account
- every hour in username.tsv file.
- """
- import os
- import random
- import sys
- import time
- import argparse
- import instabot
- import instaMaker
- import multiprocessing
- # USERNAME = "tester9209"
- # PASS = "nousername0"
- # USERNAME = "moneer7358"
- # PASS = "NubhR1991!"
- # USERNAME = "bagdidi1876"
- # PASS = "nousername0"
- # USERNAME = "bagdidi18321"
- # PASS = "nousername0"
- # USERNAME = "ahmadon7641"
- # PASS = "nousername0"
- USERNAME = ""
- PASS = ""
- def likeMediasByUsers():
- """
- instabot example
- Workflow:
- Like last medias by users.
- """
- import argparse
- import sys
- import os
- 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=USERNAME, password=PASS,
- proxy=args.proxy)
- for username in args.users:
- bot.like_user(username, filtration=False)
- def like_users():
- 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}))
- for item in follow_following_list:
- tasks_list.append((bot.follow_following, {'user_id': item}))
- # for item in like_hashtags_list:
- # tasks_list.append((bot.like_hashtag, {'hashtag': item, 'amount': None}))
- # for item in like_users_list:
- # tasks_list.append((bot.like_user, {'user_id': item, 'amount': None}))
- # shuffle(tasks_list)
- for func, arg in tasks_list:
- func(**arg)
- def comment_on_hashTags():
- """
- instabot example
- 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.
- """
- 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 = "comments.txt"
- hashtags = "dog"
- 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()
- def like_from_feed():
- """
- instabot example
- Workflow:
- Like rescent medias from your timeline feed.
- """
- 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 repost_users_posts():
- """
- instabot example
- Workflow:
- Repost best photos from users to your account
- By default bot checks username_database.txt
- The file should contain one username per line!
- """
- from tqdm import tqdm
- sys.path.append(os.path.join(sys.path[0], '../'))
- from instabot import Bot
- from instabot.bot.bot_support import read_list_from_file
- USERNAME_DATABASE = 'followed.txt'
- POSTED_MEDIAS = 'posted_medias.txt'
- def repost_best_photos(my_bot, users, amount=1):
- medias = get_not_used_medias_from_users(my_bot, users)
- medias = sort_best_medias(my_bot, medias, amount)
- for media in tqdm(medias, desc='Reposting photos'):
- repost_photo(my_bot, media)
- def sort_best_medias(my_bot, media_ids, amount=1):
- best_medias = [my_bot.get_media_info(media)[0] for media in tqdm(media_ids, desc='Getting media info')]
- best_medias = sorted(best_medias, key=lambda x: (x['like_count'], x['comment_count']), reverse=True)
- return [best_media['pk'] for best_media in best_medias[:amount]]
- def get_not_used_medias_from_users(my_bot, users=None, users_path=USERNAME_DATABASE):
- if not users:
- users = read_list_from_file(users_path)
- users = map(str, users)
- total_medias = []
- for user in users:
- medias = my_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
- def exists_in_posted_medias(new_media_id, path=POSTED_MEDIAS):
- medias = read_list_from_file(path)
- return str(new_media_id) in medias
- def update_posted_medias(new_media_id, path=POSTED_MEDIAS):
- medias = read_list_from_file(path)
- medias.append(str(new_media_id))
- with open(path, 'w') as file:
- file.writelines('\n'.join(medias))
- return True
- def repost_photo(my_bot, new_media_id, path=POSTED_MEDIAS):
- if exists_in_posted_medias(new_media_id, path):
- my_bot.logger.warning("Media {0} was uploaded earlier".format(new_media_id))
- return False
- photo_path = my_bot.download_photo(new_media_id, description=True)
- if not photo_path:
- return False
- with open(photo_path[:-3] + 'txt', 'r') as f:
- text = ''.join(f.readlines())
- if my_bot.upload_photo(photo_path, text):
- update_posted_medias(new_media_id, path)
- my_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 = read_list_from_file(args.file)
- repost_best_photos(bot, users, args.amount)
- def get_ushers_medias_list():
- bot = instabot.Bot()
- bot.login(username=USERNAME, password=PASS)
- medias_list = bot.get_user_medias("mohamdfakhri")
- bot.comments_file = "comments.txt"
- bot.comment_delay = 3
- # bot.comment_medias(medias_list)
- for item in medias_list:
- bot.comment(item, "@ludwigvonriviera")
- time.sleep(3)
- print "done"
- def initializeBot():
- bot = instabot.Bot()
- bot.login(username=USERNAME, password=PASS)
- bot.comment_delay = 3
- return bot
- def get_user_media(bot, victim):
- medias = bot.get_total_user_medias(victim)
- # medias = bot.get_user_medias(victim)
- print "Found " + str(len(medias)) + " Medias."
- return medias
- def comment_all_medias(bot, medias, victim_to_tag):
- for idx, media in enumerate(medias):
- print "Comment " + str(idx) + "."
- bot.comment(media, "@" + victim_to_tag)
- print "Comment " + str(idx) + " Done."
- time.sleep(random.randrange(5, 10))
- def upload_photo_and_tag_victim(bot, victim, photo):
- bot.upload_photo(photo, "@" + victim)
- print "Upladed Photo."
- if __name__ == '__main__':
- text_file = open("comments.txt", "r")
- comments = text_file.readlines()
- text_file.close()
- text_file = open("images.txt", "r")
- images = text_file.readlines()
- text_file.close()
- print "Do you have an Instagram account? \n 1. Yes\n No"
- choice = input()
- if choice == 1:
- print "Enter Username: "
- USERNAME = raw_input()
- print "Enter Password: "
- PASS = raw_input()
- if choice == 2:
- USERNAME, PASS = instaMaker.main()
- bot = initializeBot()
- print "What would you want to do?"
- print "1. Comment a Victim (a) on images of another Victim (b)"
- print "2. Comment sentences on a Victims images"
- print "3. Upload images and tag Victim"
- choice = input()
- if choice == 1:
- print "Enter Victim (a) - The one to be tagged:"
- victim_a = raw_input()
- print "Enter Victim (b) - The one with the images:"
- victim_b = raw_input()
- print "Getting medias"
- medias = get_user_media(bot, victim_b)
- print "Commenting"
- comment_all_medias(bot, medias, victim_a)
- quit()
- if choice == 2:
- print "Enter Victim:"
- victim = raw_input()
- # Get media list
- medias = get_user_media(bot, victim)
- # Iterate media and comment
- bot.comment_delay = 0
- for media in medias:
- bot.comment(media, random.choice(comments))
- time.sleep(random.randrange(5, 10))
- quit()
- if choice == 3:
- print "Enter Victim:"
- victim = raw_input()
- print "Enter Number of photos: 1-" + str(len(images)) + " MAX!"
- num_of_uploads = input()
- # Upload image
- for idx, curr_pic in enumerate(images):
- if idx > num_of_uploads:
- break
- print "Uploading " + str(idx + 1) + " of " + str(num_of_uploads)
- upload_photo_and_tag_victim(bot, victim, (random.choice(images)).strip())
- print "Uploaded " + str(idx + 1) + " of " + str(num_of_uploads)
- time.sleep(random.randrange(10, 20))
- quit()
- source_media_profile = "mdadaaa"
- # upload_photo_and_tag_victim(bot, "@tester9209", "Image002.jpg")
- # get_users_medias_list()
- # repost_users_posts()
- # like_from_feed()
- # comment_on_hashTags()
- # like_users()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement