Download pool/shard001/Python/0009176_feed_util.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009176_feed_util.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard001/Python/0009176_feed_util.py
-
curl -L -o 0009176_feed_util.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard001/Python/0009176_feed_util.py
1.39 kB
| """ Module that handles the like features """ | |
| # import built-in & third-party modules | |
| # import InstaPy modules | |
| from .util import update_activity | |
| # import exceptions | |
| from selenium.common.exceptions import NoSuchElementException | |
| LIKE_TAG_CLASS = "coreSpriteHeartOpen" | |
| def get_like_on_feed(browser, amount): | |
| """ | |
| browser - the selenium browser element | |
| amount - total amount of likes to perform | |
| -------------------------------------- | |
| The function takes in the total amount of likes to perform | |
| and then sends buttons to be liked, if it has run out of like | |
| buttons it will perform a scroll | |
| """ | |
| assert 1 <= amount | |
| likes_performed = 0 | |
| while likes_performed != amount: | |
| try: | |
| like_buttons = browser.find_elements_by_class_name(LIKE_TAG_CLASS) | |
| except NoSuchElementException: | |
| print("Unable to find the like buttons, aborting") | |
| break | |
| else: | |
| for button in like_buttons: | |
| likes_performed += 1 | |
| if amount < likes_performed: | |
| print("Performed the required number of likes") | |
| break | |
| yield button | |
| print("--> Total Likes uptil now ->", likes_performed) | |
| browser.execute_script("window.scrollTo(0, document.body.scrollHeight);") | |
| update_activity(browser, state=None) | |