Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from instapy import InstaPy
- import time
- import datetime
- import random
- # Write your automation here
- # Stuck ? Look at the github page or the examples in the examples folder
- log_file = open("/code/logs/cron_job_log.md", "a")
- insta_username = ''
- insta_password = ''
- comment_patterns = [
- [
- ["That's ", "It's "],
- ['beautiful', 'brilliant', 'epic', 'perfect', 'great', 'good', 'cool', 'amazing', 'magnificent', 'magical', 'lovely', 'professional', 'glorious', 'excellent', 'masterful', 'unique'],
- ['. ', '! ', '!! ', '!!! '],
- ['It', 'That'],
- [' would be '],
- ['amazing', 'great', 'cool', 'pleased'],
- [' if You would check out '],
- ['my '],
- ['profile', 'work', 'stuff', 'posts', 'account', 'music', 'productions']
- ],
- [
- ['I like it :stuck_out_tongue:', 'Like! :wink:', 'Good work! :open_mouth:', ':heart:']
- ],
- [
- ['Wow!', 'Great!', 'Awesome! :yum:', 'Good work :)', ':heart:', 'Oh my! :open_mouth:']
- ],
- ]
- def job():
- session = InstaPy(username=insta_username, password=insta_password, selenium_local_session=False)
- session.set_selenium_remote_session(selenium_url='http://selenium:4444/wd/hub')
- session.login()
- 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)
- session.set_comments(generate_comments_from_patterns(patterns=comment_patterns, amount=30))
- session.set_user_interact(amount=10, percentage=30)
- session.set_do_like(enabled=True, percentage=100)
- session.set_do_follow(enabled=False, percentage=70)
- session.set_do_comment(True, percentage=10)
- session.interact_user_followers(['revealedrec', 'hardwell', 'martingarrix', 'dimitrivegasandlikemike'], amount=10, randomize=True)
- session.end()
- def generate_comments_from_patterns(patterns=None, amount=10):
- rendered_comments = []
- build_comment = ''
- patterns = patterns or []
- for i in range(amount):
- random_patterns_table_index = random.randint(0, (len(patterns) - 1))
- selected_pattern = patterns[random_patterns_table_index]
- for row in selected_pattern:
- build_comment += row[random.randint(0, (len(row) - 1))]
- rendered_comments.append(build_comment)
- build_comment = ''
- return rendered_comments
- '''Forever and ever! (Do job every hour)'''
- while True:
- datetime_start_at = datetime.datetime.now()
- job_start_at = time.time()
- """JOB"""
- job()
- datetime_end_at = datetime.datetime.now()
- job_end_at = time.time()
- """Script deploy time"""
- d = divmod(job_end_at - job_start_at, 86400) # days
- h = divmod(d[1], 3600) # hours
- m = divmod(h[1], 60) # minutes
- s = m[1] # seconds
- log_file.write('\n' + ('#' * 86))
- log_file.write("\nSession started at: " + str(datetime_start_at) + " and ended at " + str(datetime_end_at))
- log_file.write('\nScript was working for: %d days, %d hours, %d minutes, %d seconds' % (d[0], h[0], m[0], s))
- log_file.write('\n' + ('#' * 86))
- log_file.flush()
- """Sleep to do job every hour"""
- sleep_time = 60
- if sleep_time > 0:
- time.sleep(sleep_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement