def run_cycle(username, password, delay, cycle_length, compliments, hashtags):
# Create the bot
b = Bot(username, password)
time.sleep(2)
followed_list = []
#follow people
while(len(followed_list) < cycle_length):
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'])
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'])
time.sleep(1)
followed_list.append(media[i]['owner']['id'])
time.sleep(randint(delay-5,delay+5))
if(len(followed_list) > cycle_length):
break
if(len(followed_list) > cycle_length):
break
except Exception as e:
print(str(e))
time.sleep(delay)
#clean up
clean(username, password, delay, b)
评论列表
文章目录