class Scraper(): def __init__(self, username, password): self.username = username self.password = password self.scraper = Instagram() self.scraper.with_credentials(username, password) self.scraper.login() def target_by_username(self, target_name, tweet_count=None): rows = [[ 'username', 'full name', 'biography', 'prive', 'verfied', 'picture' ]] target = self.scraper.get_account(target_name) if not tweet_count: tweet_count = target.follows_count followers = self.scraper.get_followers(target.identifier, tweet_count, 100, delayed=True) for item in followers['accounts']: rows.append([ item.username, item.full_name, item.biography, item.is_private, item.is_verified, item.profile_pic_url ]) return rows
def start(): while True: try: print("iter") instagram = Instagram() instagram.with_credentials(insta_username, insta_password) instagram.login(force=False,two_step_verificator=True) sleep(2) # Delay to mimic user followers = [] account = instagram.get_account(username) sleep(1) curr_time = datetime.datetime.now(timezone('Asia/Kolkata')) curr_time = curr_time.strftime("%b %d, %Y - %H:%M:%S") followers = instagram.get_followers(account.identifier, FOLLOWER_LIMIT, 100, delayed=True) # Get 150 followers of 'kevin', 100 a time with random delay between requests # print(followers) current_followers = [] for follower in followers['accounts']: current_followers.append(follower.username) del followers if not path.exists("follower_list.txt"): f = open("follower_list.txt","w") f.write(str(current_followers)) f.close() else: f = open("follower_list.txt","r+") old_followers = f.read() f.close() old_followers = ast.literal_eval(old_followers) unfollowers = check_unfollowers(current_followers,old_followers) followers = check_followers(current_followers,old_followers) follower_change = len(current_followers)-len(old_followers) follow_count = len(followers) unfollow_count = len(unfollowers) discord_webhook.send_msg(username,follower_change,followers,unfollowers,follow_count,unfollow_count,curr_time,discord_webhook_url) f = open("follower_list.txt","w") f.write(str(current_followers)) f.close() except KeyboardInterrupt: print("Exiting...") sys.exit(0) except Exception as e: print(e) sleep(MINS_TO_SLEEP*60)
def __init__(this, user1, user2): this.user1 = user1 this.user2 = user2 instagram = Instagram() instagram.with_credentials('*****@*****.**', 'Yakapus0123') instagram.login() sleep(3) user1FollowersList = [] user2FollowersList = [] this.mutualFollowers = [] account1 = instagram.get_account(this.user1) sleep(2) account2 = instagram.get_account(this.user2) sleep(2) user1Followers = instagram.get_followers(account1.identifier, account1.followed_by_count, 100, delayed=True) user2Followers = instagram.get_followers(account2.identifier, account1.followed_by_count, 100, delayed=True) print(user1Followers) for f in user1Followers['accounts']: user1FollowersList.append(f.username) for f in user2Followers['accounts']: user2FollowersList.append(f.username) this.mutualFollowers = set(user1FollowersList) & set( user2FollowersList)
instagram.with_credentials('', '') instagram.login() #Getting an account by id account = instagram.get_account('bluck') # Available fields '''print('Account info:') print('Id: ', account.identifier) print('Username: '******'Full name: ', account.full_name) print('Biography: ', account.biography) print('External Url: ', account.external_url) print('Number of published posts: ', account.media_count) print('Number of followers: ', account.followed_by_count) print('Number of follows: ', account.follows_count) print('Is private: ', account.is_private) print('Is verified: ', account.is_verified)''' followers = instagram.get_followers(account.identifier, 90, 90, delayed=True) for follower in followers['accounts']: print('bluck ', follower.username) account = instagram.get_account('erick.rojas.988') followers = instagram.get_followers(account.identifier, 90, 90, delayed=True) for follower in followers['accounts']: print('eric ', follower.username) # or simply for printing use #print(account)
#TODO does not work currently instagram changed api from igramscraper.instagram import Instagram from time import sleep instagram = Instagram() instagram.with_credentials('username', 'password', 'path/to/cache/folder') instagram.login() sleep(2) # Delay to mimic user username = '******' followers = [] account = instagram.get_account(username) sleep(1) followers = instagram.get_followers( account.identifier, 1000, 100, True ) # Get 1000 followers of 'kevin', 100 a time with random delay between requests print(followers)
class InstaAgent(): def __init__(self, username, password): self.username = username self.password = password self.scraper = Instagram() self.target = self.scraper.get_account(username) self.scraper.with_credentials(username, password) self.scraper.login() def get_following_data(self, target_name, tweet_count=None): rows = [[ 'username', 'full name', 'biography', 'prive', 'verfied', 'picture' ]] target = self.scraper.get_account(target_name) if not tweet_count: tweet_count = target.follows_count followers = self.scraper.get_following(target.identifier, tweet_count, 100, delayed=True) for item in followers['accounts']: rows.append([ item.username, item.full_name, item.biography, item.is_private, item.is_verified, item.profile_pic_url ]) return rows def get_followers_data(self, target_name, tweet_count=None): rows = [[ 'username', 'full name', 'biography', 'prive', 'verfied', 'picture' ]] target = self.scraper.get_account(target_name) if not tweet_count: tweet_count = target.follows_count followers = self.scraper.get_followers(target.identifier, tweet_count, 100, delayed=True) for item in followers['accounts']: rows.append([ item.username, item.full_name, item.biography, item.is_private, item.is_verified, item.profile_pic_url ]) return rows def substract_folowing_folowers(self, target): following = self.get_following_data(target, tweet_count=650) followers = self.get_followers_data(target, tweet_count=650) res = [ i for i in following if (i not in followers and not i.is_verified) ] res.index(following[0], 0) with open('./CSVs/' + target + '__following.csv', mode='w') as csvfile: writer = csv.writer(csvfile) writer.writerows(following) with open('./CSVs/' + target + '__followers.csv', mode='w') as csvfile: writer = csv.writer(csvfile) writer.writerows(followers) with open('./CSVs/' + target + '__substract.csv', mode='w') as csvfile: writer = csv.writer(csvfile) writer.writerows(res) def unfollow_list(self, lst): for i in lst: try: target = self.scraper.get_account(i) self.scraper.unfollow(target.identifier) print('unfollowed: ' + i) except Exception as e: print(e)
# Open the file where to collect the real instagram user toke from the following of the above trusted users file = open('../usernames/fake_users_ds.txt', 'a') fakeUsersSet = set() # For every username in the list take the first N followers and fill the real_users.txt file for username in users: print(username) fakeUsersSet.add(username) #Add also the trusted fake sleep(10) account = instagram.get_account(username) sleep(2) #Set how many followers you want to obtain num_followers = 100 print(account.followed_by_count) # If the followers of the user are less take all the followers if (account.follows_count < num_followers): num_followers = account.followed_by_count followers = instagram.get_followers(account.identifier, num_followers, num_followers, delayed=True) #For every user, append it in the list for follower in followers['accounts']: fakeUsersSet.add(follower.username) file.write(follower.username + '\n')
# manual setting my_username = '' my_password = '' max_followers = 10000 # authentication supported instagram = Instagram() instagram.with_credentials(my_username, my_password) instagram.login(two_step_verificator=True) account = instagram.get_account(my_username) # see who doesn't follow back # Get 'max_followers' followers of the user, 100 a time with random delay between requests followers = instagram.get_followers(account.identifier, max_followers, 100, delayed=True) following = instagram.get_following(account.identifier, max_followers, 100, delayed=True) followers_name = [[follower.username, follower.full_name] for follower in followers['accounts']] # a list of list following_name = [[following_user.username, following_user.full_name] for following_user in following['accounts']] if not os.path.exists(r'./output/' + my_username): os.makedirs(r'./output/' + my_username) with open(r'./output/' + my_username + r'/not_follow_back.csv',
def start(request): request_json = request.get_json() insta_username = request_json['insta_username'] insta_password = request_json['insta_password'] username = request_json['username'] discord_webhook_url = request_json['discord_webhook_url'] try: instagram = Instagram() instagram.with_credentials(insta_username, insta_password) instagram.login(force=False, two_step_verificator=True) sleep(2) # Delay to mimic user followers = [] account = instagram.get_account(username) sleep(1) curr_time = datetime.datetime.now(timezone('US/Eastern')) curr_time = curr_time.strftime("%b %d, %Y - %H:%M:%S") followers = instagram.get_followers( account.identifier, FOLLOWER_LIMIT, 100, delayed=True ) # Get 150 followers of 'kevin', 100 a time with random delay between requests # print(followers) followings = instagram.get_following(account.identifier, FOLLOWER_LIMIT, 100, delayed=True) current_followers = [] current_followings = [] for following in followings['accounts']: current_followings.append(following.username) for follower in followers['accounts']: current_followers.append(follower.username) del followers del followings not_follow_back = check_not_followback(current_followings, current_followers) if not path.exists(username + "_follower_list.txt"): f = open(username + "_follower_list.txt", "w") f.write(str(current_followers)) f.close() else: f = open(username + "_follower_list.txt", "r+") old_followers = f.read() f.close() old_followers = ast.literal_eval(old_followers) unfollowers = check_unfollowers(current_followers, old_followers) followers = check_followers(current_followers, old_followers) follower_change = len(current_followers) - len(old_followers) follow_count = len(followers) unfollow_count = len(unfollowers) discord_webhook.send_msg(username, follower_change, followers, unfollowers, follow_count, unfollow_count, curr_time, discord_webhook_url, not_follow_back) retMap = { 'username': username, 'follower_change': follower_change, 'followers': followers, 'unfollowers': unfollowers, 'follow_count': follow_count, 'unfollow_count': unfollow_count, 'curr_time': curr_time, 'discord_webhook_url': discord_webhook_url, 'not_follow_back': not_follow_back } f = open(username + "_follower_list.txt", "w") f.write(str(current_followers)) f.close() retJson = json.dumps(retMap) except Exception as e: print(e)
def create_export(): filename = get_file_name() username = input("Type your username: "******"Type your password: "******"Type the number of people you are following: ")) instagram = Instagram() instagram.with_credentials(username, password, './cache/') try: instagram.login(force=False,two_step_verificator=True) except Exception as e: print(e) print('Incorrect credentials. Relaunch and try again.') return False sleep(2) # Delay to mimic user account = instagram.get_account(username) print(bcolors.OKGREEN + 'Connected to account ' + bcolors.BOLD + account.full_name + ' @' + account.username + bcolors.ENDC) print("Export date: ", today.strftime("%d/%m/%Y")) loading() sleep(1) followers = instagram.get_followers(account.identifier, 400, 100, delayed=True) # Get 400 followers of 'kevin', 100 a time with random delay between requests # Delay to mimic user sleep(1) following = instagram.get_following(account.identifier, nbFollow, 100, delayed=True) if filename != '': with open('./export/' + filename, 'w') as csvfile: filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) filewriter.writerow(['Followers']) for follower in followers['accounts']: filewriter.writerow([follower.username, follower.full_name]) filewriter.writerow(['Total: ' + str(len(followers['accounts']))]) filewriter.writerow(['']) filewriter.writerow(['Following']) for follow in following['accounts']: filewriter.writerow([follow.username, follow.full_name]) filewriter.writerow(['Total: ' + str(len(following['accounts']))]) filewriter.writerow(['']) filewriter.writerow(['People I follow that do not follow me']) for follow in following['accounts']: if contains(followers['accounts'], lambda x: x.username == follow.username) == False: if follow.is_verified == False: bastards.append(follow) for bastard in bastards: filewriter.writerow([bastard.username, bastard.full_name]) filewriter.writerow(['Total: ' + str(len(bastards))]) filewriter.writerow(['']) filewriter.writerow(['People I do not follow that follow me']) for follower in followers['accounts']: if contains(following['accounts'], lambda x: x.username == follower.username) == False: miskines.append(follower) for miskine in miskines: filewriter.writerow([miskine.username, miskine.full_name]) filewriter.writerow(['Total: ' + str(len(miskines))]) filewriter.writerow(['']) filewriter.writerow(['Verified account I follow']) for follow in following['accounts']: if follow.is_verified == True: verifiedFollow.append(follow) for verified in verifiedFollow: filewriter.writerow([verified.username, verified.full_name]) filewriter.writerow(['Total: ' + str(len(verifiedFollow))]) filewriter.writerow(['']) filewriter.writerow(['Verified account that follow me']) for follower in followers['accounts']: if follower.is_verified == True: verifiedFollowers.append(follower) for verified in verifiedFollowers: filewriter.writerow([verified.username, verified.full_name]) filewriter.writerow(['Total: ' + str(len(verifiedFollowers))]) filewriter.writerow(['']) filewriter.writerow(['Date: ' + today.strftime("%d/%m/%Y")]) print('Export ' + filename + ' finished')
def start(): iterno = 0 while True: try: iterno = iterno + 1 print("Checking For unfollows ") print("Loop No.", iterno) instagram = Instagram() instagram.with_credentials(insta_username, insta_password) instagram.login(force=False, two_step_verificator=True) sleep(2) followers = [] account = instagram.get_account(username) sleep(2) curr_time = datetime.datetime.now(timezone('Asia/Kolkata')) curr_time = curr_time.strftime("%b %d, %Y - %H:%M:%S") followers = instagram.get_followers(account.identifier, 10**6, 150, delayed=True) current_followers = [] for follower in followers['accounts']: current_followers.append(follower.username) del followers if not path.exists("Follower_List.txt"): f = open("Follower_List.txt", "w") f.write(str(current_followers)) f.close() else: f = open("Follower_List.txt", "r+") old_followers = f.read() f.close() old_followers = ast.literal_eval(old_followers) unfollowers = check_unfollowers(current_followers, old_followers) followers = check_followers(current_followers, old_followers) follower_change = len(current_followers) - len(old_followers) follow_count = len(followers) unfollow_count = len(unfollowers) discord_webhook.send_msg(insta_username, insta_password, username, follower_change, followers, unfollowers, follow_count, unfollow_count, curr_time, discord_webhook_url, ufforuf, fof) f = open("Follower_List.txt", "w") f.write(str(current_followers)) f.close() except KeyboardInterrupt: print("Exiting...") sys.exit(0) except Exception as e: print(e) sleep(SLEEP_MINS * 60)