Check the given link if it is appropriate :param browser: The selenium webdriver instance :param post_link: :param dont_like: hashtags of inappropriate phrases :param mandatory_words: words of appropriate phrases :param ignore_if_contains: :param logger: the logger inst
(
browser,
post_link,
dont_like,
mandatory_words,
mandatory_language,
mandatory_character,
is_mandatory_character,
check_character_set,
ignore_if_contains,
logger,
)
| 549 | |
| 550 | |
| 551 | def check_link( |
| 552 | browser, |
| 553 | post_link, |
| 554 | dont_like, |
| 555 | mandatory_words, |
| 556 | mandatory_language, |
| 557 | mandatory_character, |
| 558 | is_mandatory_character, |
| 559 | check_character_set, |
| 560 | ignore_if_contains, |
| 561 | logger, |
| 562 | ): |
| 563 | """ |
| 564 | Check the given link if it is appropriate |
| 565 | |
| 566 | :param browser: The selenium webdriver instance |
| 567 | :param post_link: |
| 568 | :param dont_like: hashtags of inappropriate phrases |
| 569 | :param mandatory_words: words of appropriate phrases |
| 570 | :param ignore_if_contains: |
| 571 | :param logger: the logger instance |
| 572 | :return: tuple of |
| 573 | boolean: True if inappropriate, |
| 574 | string: the username, |
| 575 | boolean: True if it is video media, |
| 576 | string: the message if inappropriate else 'None', |
| 577 | string: set the scope of the return value |
| 578 | """ |
| 579 | |
| 580 | # Check URL of the webpage, if it already is post's page, then do not |
| 581 | # navigate to it again |
| 582 | web_address_navigator(browser, post_link) |
| 583 | |
| 584 | # Check if the Post is Valid/Exists |
| 585 | post_page = get_additional_data(browser) |
| 586 | |
| 587 | if post_page is None: |
| 588 | logger.warning("Unavailable Page: {}".format(post_link.encode("utf-8"))) |
| 589 | return True, None, None, "Unavailable Page", "Failure" |
| 590 | |
| 591 | # Gets the description of the post's link and checks for the dont_like tags |
| 592 | graphql = "graphql" in post_page |
| 593 | location_name = None |
| 594 | |
| 595 | if graphql: |
| 596 | media = post_page["graphql"]["shortcode_media"] |
| 597 | is_video = media["is_video"] |
| 598 | user_name = media["owner"]["username"] |
| 599 | image_text = media["edge_media_to_caption"]["edges"] |
| 600 | image_text = image_text[0]["node"]["text"] if image_text else None |
| 601 | location = media["location"] |
| 602 | location_name = location["name"] if location else None |
| 603 | media_edge_string = get_media_edge_comment_string(media) |
| 604 | # Gets all comments on media |
| 605 | comments = ( |
| 606 | media[media_edge_string]["edges"] |
| 607 | if media[media_edge_string]["edges"] |
| 608 | else None |
no test coverage detected