Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. from instapy import InstaPy
  2. import time
  3. import datetime
  4. import random
  5.  
  6. # Write your automation here
  7. # Stuck ? Look at the github page or the examples in the examples folder
  8.  
  9. log_file = open("/code/logs/cron_job_log.md", "a")
  10.  
  11. insta_username = ''
  12. insta_password = ''
  13.  
  14. comment_patterns = [
  15. [
  16. ["That's ", "It's "],
  17. ['beautiful', 'brilliant', 'epic', 'perfect', 'great', 'good', 'cool', 'amazing', 'magnificent', 'magical', 'lovely', 'professional', 'glorious', 'excellent', 'masterful', 'unique'],
  18. ['. ', '! ', '!! ', '!!! '],
  19. ['It', 'That'],
  20. [' would be '],
  21. ['amazing', 'great', 'cool', 'pleased'],
  22. [' if You would check out '],
  23. ['my '],
  24. ['profile', 'work', 'stuff', 'posts', 'account', 'music', 'productions']
  25. ],
  26. [
  27. ['I like it :stuck_out_tongue:', 'Like! :wink:', 'Good work! :open_mouth:', ':heart:']
  28. ],
  29. [
  30. ['Wow!', 'Great!', 'Awesome! :yum:', 'Good work :)', ':heart:', 'Oh my! :open_mouth:']
  31. ],
  32. ]
  33.  
  34.  
  35. def job():
  36. session = InstaPy(username=insta_username, password=insta_password, selenium_local_session=False)
  37. session.set_selenium_remote_session(selenium_url='http://selenium:4444/wd/hub')
  38. session.login()
  39. session.set_relationship_bounds(enabled=False, potency_ratio=-0.7, delimit_by_numbers=True, max_followers=4590, max_following=5555, min_followers=None, min_following=40)
  40. session.set_comments(generate_comments_from_patterns(patterns=comment_patterns, amount=30))
  41. session.set_user_interact(amount=10, percentage=30)
  42. session.set_do_like(enabled=True, percentage=100)
  43. session.set_do_follow(enabled=False, percentage=70)
  44. session.set_do_comment(True, percentage=10)
  45. session.interact_user_followers(['revealedrec', 'hardwell', 'martingarrix', 'dimitrivegasandlikemike'], amount=10, randomize=True)
  46. session.end()
  47.  
  48.  
  49. def generate_comments_from_patterns(patterns=None, amount=10):
  50. rendered_comments = []
  51. build_comment = ''
  52. patterns = patterns or []
  53.  
  54. for i in range(amount):
  55. random_patterns_table_index = random.randint(0, (len(patterns) - 1))
  56. selected_pattern = patterns[random_patterns_table_index]
  57. for row in selected_pattern:
  58. build_comment += row[random.randint(0, (len(row) - 1))]
  59. rendered_comments.append(build_comment)
  60. build_comment = ''
  61.  
  62. return rendered_comments
  63.  
  64.  
  65.  
  66. '''Forever and ever! (Do job every hour)'''
  67. while True:
  68. datetime_start_at = datetime.datetime.now()
  69. job_start_at = time.time()
  70.  
  71. """JOB"""
  72. job()
  73.  
  74. datetime_end_at = datetime.datetime.now()
  75. job_end_at = time.time()
  76.  
  77. """Script deploy time"""
  78. d = divmod(job_end_at - job_start_at, 86400) # days
  79. h = divmod(d[1], 3600) # hours
  80. m = divmod(h[1], 60) # minutes
  81. s = m[1] # seconds
  82.  
  83. log_file.write('\n' + ('#' * 86))
  84. log_file.write("\nSession started at: " + str(datetime_start_at) + " and ended at " + str(datetime_end_at))
  85. log_file.write('\nScript was working for: %d days, %d hours, %d minutes, %d seconds' % (d[0], h[0], m[0], s))
  86. log_file.write('\n' + ('#' * 86))
  87.  
  88. log_file.flush()
  89.  
  90. """Sleep to do job every hour"""
  91. sleep_time = 60
  92. if sleep_time > 0:
  93. time.sleep(sleep_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement