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

How to add bedtime and random delay #1054

Closed jasonywh closed 4 years ago

jasonywh commented 5 years ago

Can anyone pls help me add a code to make it run in day time only & sleep at night time ? currently the below code auto post only 1 photo every 24 hours, but I want it to auto post around 5 photo on day time & after that pause on night time, then resume posting on next day, also I need to have random delay between 5 post to make it more natural

import glob

import os

import sys

import time

from io import open

sys.path.append(os.path.join(sys.path[0], "../../"))

from instabot import Bot  # noqa: E402



posted_pic_list = []

try:
    
      with open("pics.txt", "r", encoding="utf8") as f:

           posted_pic_list = f.read().splitlines()

except Exception:
    posted_pic_list = []



timeout = 24 * 60 * 60  # pics will be posted every 24 hours



bot = Bot()

bot.login()



while True:
    
      folder_path = "./pics"
    
      pics = glob.glob(folder_path + "/*.jpg")
    
      pics = sorted(pics)
    
      try:
        
            for pic in pics:
            
                  if pic in posted_pic_list:
                
                           continue

            

             pic_name = pic[:-4].split("-")
            
             pic_name = "-".join(pic_name[1:])

            

             print("upload: " + pic_name)

            
             description_file = folder_path + "/" + pic_name + '.txt'

            
             if os.path.isfile(description_file):
                
                   with open(description_file, 'r') as file:
                    
                            caption = file.read()
            
              else:
                
                            caption = pic_name.replace("-", " ")

            

              bot.upload_photo(pic, caption=caption)
            
              if bot.api.last_response.status_code != 200:
                
                     print(bot.api.last_response)
                
                     # snd msg
                
                     break

            

               if pic not in posted_pic_list:
                
                     posted_pic_list.append(pic)
                
                     with open("pics.txt", "a", encoding="utf8") as f:
                    
                             f.write(pic + "\n")

            

               time.sleep(timeout)

    

       except Exception as e:
        
              print(str(e))
    
        time.sleep(60)


thanks in advance if anyone can pls help me modify this

williamyorkl commented 5 years ago

simple way : you can use the mod, add a counter, every loop ,then the counter +1, after the the counter reaches random.randiant(8,12) ,then run the scripts again. :-)

ghost commented 5 years ago

please use schedule.

for example :

https://github.com/instagrambot/instabot/blob/master/examples/ultimate_schedule/ultimate.py

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.