ohld / igbot

🐙 Free scripts, bots and Python API wrapper. Get free followers with our auto like, auto follow and other scripts!
https://hikerapi.com/p/N2P6iqiM
Apache License 2.0
4.71k stars 1.47k forks source link

Comment on user's follower's media - comment_user() Error #425

Closed miranthajayatilake closed 6 years ago

miranthajayatilake commented 6 years ago

I was trying to use comment_user and comment_users functions to comment of user's follower's media.

below is the code

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(comments_file='comments.txt')
bot.login(username=args.u, password=args.p,
          proxy=args.proxy)

for username in args.users:
    follower_ids = bot.get_user_followers(username, 100)

    bot.comment_users(follower_ids, ncomments=1)`

And this gives the below error

Traceback (most recent call last):
  File "comment_user_followers.py", line 32, in <module>
    bot.comment_users(follower_ids, ncomments=1)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot.py", line 449, in comment_users
    return comment_users(self, user_ids, ncomments)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot_comment.py", line 71, in comment_users
    self.comment_user(user_id, amount=ncomments)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot.py", line 446, in comment_user
    return comment_user(self, user_id, amount)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot_comment.py", line 58, in comment_user
    medias = self.get_user_medias(user_id, is_comment=True)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot.py", line 234, in get_user_medias
    return get_user_medias(self, user_id, filtration, is_comment)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot_get.py", line 52, in get_user_medias
    return self.filter_medias(self.LastJson["items"], filtration, is_comment=is_comment)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot.py", line 477, in filter_medias
    return filter_medias(self, media_items, filtration, quiet, is_comment)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot_filter.py", line 36, in filter_medias
    media_items = _filter_medias_not_commented(self, media_items)
  File "C:\Users\miranthaj\AppData\Local\Programs\Python\Python35\lib\site-packages\instabot\bot\bot_filter.py", line 55, in _filter_medias_not_commented
    my_comments = [comment for comment in media['comments'] if comment['user_id'] == self.user_id]
KeyError: 'comments'`

Please let me what I'm doing wrong here.

Thank you!

amitchoudhary13 commented 6 years ago

want to comment only on the first media post?

miranthajayatilake commented 6 years ago

Yeah. That'll be fine.

sudoguy commented 6 years ago

Fixed https://github.com/instagrambot/instabot/commit/27e39b1982a332426050be6f451d1a2c270245d8