Advertisement
Guest User

Ultimate

a guest
Mar 26th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.70 KB | None | 0 0
  1. import schedule
  2. import time
  3. import sys
  4. import os
  5. import random
  6. import yaml             #->added to make pics upload -> see job8
  7. import glob             #->added to make pics upload -> see job8
  8. from tqdm import tqdm
  9. import threading        #->added to make multithreadening possible -> see fn run_threaded
  10.  
  11. sys.path.append(os.path.join(sys.path[0],'../../'))
  12. from instabot import Bot
  13.  
  14. bot = Bot(comments_file="comments.txt")
  15. bot.login()
  16. bot.logger.info("ULTIMATE script. 24hours save")
  17.  
  18. comments_file_name = "comments.txt"
  19. random_user_file = bot.read_list_from_file("username_database.txt")
  20. random_hashtag_file = bot.read_list_from_file("hashtag_database.txt")
  21.  
  22. #to get pics and autopost it
  23. posted_pic_list = []
  24. try:
  25.     with open('pics.txt', 'r') as f:
  26.         posted_pic_list = f.read().splitlines()
  27. except:
  28.     posted_pic_list = []
  29. #!!-> to work this feature properly write full/absolute path to .jgp files as follows ->v
  30. pics = glob.glob("/home/user/instagram/instabot/examples/ultimate_schedule/pics/*.jpg")  #!!change this
  31. pics = sorted(pics)
  32. #end of pics processing
  33.  
  34. #fn to return random value for separate jobs
  35. def get_random(from_list):
  36.     _random=random.choice(from_list)
  37.     print("Random from ultimate.py script is chosen: \n" + _random + "\n")
  38.     return _random
  39.  
  40. def job1(): bot.like_hashtag(get_random(random_hashtag_file), amount=int(700/24))
  41. def job2(): bot.like_timeline(amount=int(300/24))
  42. def job3(): bot.like_followers(get_random(random_user_file), nlikes=3)
  43. def job4(): bot.follow_followers(get_random(random_user_file))
  44. def job5(): bot.comment_medias(bot.get_timeline_medias())
  45. def job6(): bot.unfollow_non_followers()
  46. def job7(): bot.follow_users(bot.get_hashtag_users(get_random(random_hashtag_file)))
  47. def job8(): #-->fn to upload photos /auto_uploader
  48.     try:
  49.         for pic in pics:
  50.             if pic in posted_pic_list:
  51.                 continue
  52.             hashtags = "/>\n​​#instabot #vaskokorobko #kyiv"       #add custom hashtags
  53.             caption = pic[:-4].split(" ")                        #caption is made from the name of file
  54.             caption = " ".join(caption[1:])
  55.             caption = "\n<" + caption + hashtags                 #create full caption with hashtags
  56.             print("upload: " + caption)
  57.             bot.uploadPhoto(pic, caption=caption)
  58.             if bot.LastResponse.status_code != 200:
  59.                 print("Smth went wrong. Read the following ->\n")
  60.                 print(bot.LastResponse)
  61.                 # snd msg
  62.                 break
  63.  
  64.             if not pic in posted_pic_list:
  65.                 posted_pic_list.append(pic)
  66.                 with open('pics.txt', 'a') as f:
  67.                     f.write(pic + "\n")
  68.                 print("Succsesfully uploaded: " + pic)
  69.                 break
  70.     except Exception as e:
  71.         print(str(e))
  72. #end of job8
  73.  
  74. #function to make threads -> details here http://bit.ly/faq_schedule
  75. def run_threaded(job_fn):
  76.     job_thread=threading.Thread(target=job_fn)
  77.     job_thread.start()
  78.  
  79. schedule.every(8).hours.do(run_threaded, job1)              #like hashtag
  80. schedule.every(2).hours.do(run_threaded, job2)              #like timeline
  81. schedule.every(1).days.at("16:00").do(run_threaded, job3)   #like followers of users from file
  82. schedule.every(2).days.at("11:00").do(run_threaded, job4)   #follow followers
  83. schedule.every(16).hours.do(run_threaded, job5)             #comment medias
  84. schedule.every(1).days.at("08:00").do(run_threaded, job6)   #unfollow non-followers
  85. schedule.every(12).hours.do(run_threaded, job7)             #follow users from hashtag from file
  86. schedule.every(1).days.at("21:28").do(run_threaded, job8)   #upload pics
  87.  
  88. while True:
  89.     schedule.run_pending()
  90.     time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement