MCPcopy
hub / github.com/InstaPy/InstaPy / comment_image

Function comment_image

instapy/comment_util.py:70–149  ·  view source on GitHub ↗

Checks if it should comment on the image

(browser, username, comments, blacklist, logger, logfolder)

Source from the content-addressed store, hash-verified

68
69
70def comment_image(browser, username, comments, blacklist, logger, logfolder):
71 """Checks if it should comment on the image"""
72 # check action availability
73 if quota_supervisor("comments") == "jump":
74 return False, "jumped"
75
76 rand_comment = random.choice(comments).format(username)
77 rand_comment = emoji.demojize(rand_comment)
78 rand_comment = emoji.emojize(rand_comment, use_aliases=True)
79
80 open_comment_section(browser, logger)
81 # wait, to avoid crash
82 sleep(3)
83 comment_input = get_comment_input(browser)
84
85 try:
86 if len(comment_input) > 0:
87 # wait, to avoid crash
88 sleep(2)
89 comment_input = get_comment_input(browser)
90 # below, an extra space is added to force
91 # the input box to update the reactJS core
92 comment_to_be_sent = rand_comment
93
94 # wait, to avoid crash
95 sleep(2)
96 # click on textarea/comment box and enter comment
97 (
98 ActionChains(browser)
99 .move_to_element(comment_input[0])
100 .click()
101 .send_keys(comment_to_be_sent)
102 .perform()
103 )
104 # wait, to avoid crash
105 sleep(2)
106 # post comment / <enter>
107 (
108 ActionChains(browser)
109 .move_to_element(comment_input[0])
110 .send_keys(Keys.ENTER)
111 .perform()
112 )
113
114 update_activity(
115 browser,
116 action="comments",
117 state=None,
118 logfolder=logfolder,
119 logger=logger,
120 )
121
122 if blacklist["enabled"] is True:
123 action = "commented"
124 add_user_to_blacklist(
125 username, blacklist["campaign"], action, logger, logfolder
126 )
127 else:

Callers 3

process_commentsFunction · 0.85
interact_by_commentsMethod · 0.85
engage_with_postsMethod · 0.85

Calls 9

quota_supervisorFunction · 0.90
open_comment_sectionFunction · 0.85
sleepFunction · 0.85
get_comment_inputFunction · 0.85
update_activityFunction · 0.85
add_user_to_blacklistFunction · 0.85
EventClass · 0.85
get_action_delayFunction · 0.85
commentedMethod · 0.80

Tested by

no test coverage detected