def run_bot(username, password, delay, pipe_depth, number_of_tags, compliments, hashtags):
# Create the bot
b = Bot(username, password)
time.sleep(2)
followed_list = []
for i in range(number_of_tags):
try:
#get the media for a random hashtag
tag = hashtags[randint(0,len(hashtags)-1)].strip()
media = b.get_media_from_hashtag(tag)
#iterate through, like all and comment on a few
for i in range(len(media)):
b.like(media[i]['id'], tag)
time.sleep(1)
if(randint(0,9) == 0):
b.comment(compliments[randint(0, len(compliments)-1)], media[i]['id'], tag)
time.sleep(1)
b.follow(media[i]['owner']['id'], tag)
time.sleep(1)
followed_list.append(media[i]['owner']['id'])
rand_delay = randint(delay-5,delay+5)/2
time.sleep(rand_delay)
if(len(followed_list) > pipe_depth):
b.unfollow(followed_list[0])
followed_list.pop(0)
time.sleep(rand_delay)
except Exception as e:
print(str(e))
time.sleep(delay)
#clean up
for user in followed_list:
b.unfollow(user)
评论列表
文章目录