MCPcopy
hub / github.com/InstaPy/InstaPy / verify_commented_image

Function verify_commented_image

instapy/comment_util.py:355–390  ·  view source on GitHub ↗

Fetch comments data on posts to determine if already commented

(browser, link, owner, logger)

Source from the content-addressed store, hash-verified

353
354
355def verify_commented_image(browser, link, owner, logger):
356 """Fetch comments data on posts to determine if already commented"""
357
358 web_address_navigator(browser, link)
359
360 # wait for page fully load [IMPORTANT!]
361 explicit_wait(browser, "PFL", [], logger, 10)
362
363 try:
364 commenter = None
365 comment = None
366 data = getMediaData("edge_media_to_parent_comment", browser)
367 for value in data["edges"]:
368 commenter = value["node"]["owner"]["username"]
369 comment = value["node"]["text"]
370
371 if commenter and commenter == owner:
372 message = (
373 "--> The post has already been commented on before: '{}'".format(
374 comment
375 )
376 )
377 return True, message
378
379 except NoSuchElementException:
380 # Cannot be determined if the post has been comment by InstaPy user,
381 # and then it will not be commented until next loop, maybe comments
382 # on the post have been limited. Return True, to emulate or assume the
383 # post has been commented by user.
384 message = (
385 "--> Failed to get comments on this post, will not comment the post..."
386 )
387 return True, message
388
389 message = "--> Could not found owner's comment in this post, trying to comment..."
390 return None, message
391
392
393def process_comments(

Callers 1

process_commentsFunction · 0.85

Calls 3

web_address_navigatorFunction · 0.85
explicit_waitFunction · 0.85
getMediaDataFunction · 0.85

Tested by

no test coverage detected