Skip to content

Commit

Permalink
Merge pull request InstaPy#2612 from InfinityWebMe/master
Browse files Browse the repository at this point in the history
Feature - mandatory like
  • Loading branch information
timgrossmann authored Aug 7, 2018
2 parents dec5da7 + a141188 commit 1645d61
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Table of Contents
* [Like by Locations](#like-by-locations)
* [Like by Tags](#like-by-tags)
* [Like by Feeds](#like-by-feeds)
* [Mandatory Words](#mandatory-words)
* [Restricting Likes](#restricting-likes)
* [Ignoring Users](#ignoring-users)
* [Ignoring Restrictions](#ignoring-restrictions)
Expand Down Expand Up @@ -701,6 +702,15 @@ session.set_smart_hashtags(['cycling', 'roadbike'], limit=3, sort='top', log_tag
session.like_by_tags(amount=10, use_smart_hashtags=True)
```

### Mandatory Words

```python
session.set_mandatory_words(['#food', '#instafood'])
```

`.set_mandatory_words` searches the description and owner comments for words and
will like the image if **all** of those words are in there

### Restricting Likes

```python
Expand Down Expand Up @@ -801,7 +811,7 @@ Every time you grab `Followers` data in `"full"` range of **any** user, it is al
+ As a **result**, `live_match=False` saves lots of `precious time` and `server requests`.
+ `live_match=True`:
+ It will **always** load `live` data from the server at _requested range_.

`store_locally`:
Gives the _option_ to `save` the loaded `Followers` data in a **local storage**
The files will be saved _into_ your **logs folder**, `~/InstaPy/logs/YourOwnUsername/relationship_data/Popeye/followers/` directory.
Expand Down Expand Up @@ -861,7 +871,7 @@ Every time you grab `Following` data in `"full"` range of **any** user, it is al
+ As a **result**, `live_match=False` saves lots of `precious time` and `server requests`.
+ `live_match=True`:
+ It will **always** load `live` data from the server at _requested range_.

`store_locally`:
Gives the _option_ to `save` the loaded `Following` data in a **local storage**
The files will be saved _into_ your **logs folder**, `~/InstaPy/logs/YourOwnUsername/relationship_data/lazy.smurf/following/` directory.
Expand Down Expand Up @@ -922,7 +932,7 @@ Defines the track to choose a file to compare for `"day"`, `"month"` and `"year"
+ `"first"` selects the first record from the given `day`, `month` or `year`
+ `"median"` selects the median (_the one in the middle_) record from the given `day`, `month` or `year`
+ `"last"` selects the last record from the given `day`, `month` or `year`

`live_match`:
Defines the method of grabbing **new** `Followers` data to compare with **existing** data
> **Knowledge Base**:
Expand All @@ -936,7 +946,7 @@ Every time you grab `Followers` data in `"full"` range of **any** user, it is al
+ As a **result**, `live_match=False` saves lots of `precious time` and `server requests`.
+ `live_match=True`:
+ It will **always** load `live` data from the server at _requested range_.

`store_locally`:
Gives the _option_ to `save` the loaded `Unfollowers` data in a **local storage**
There will be 2 files saved in their own directory:
Expand All @@ -946,7 +956,7 @@ There will be 2 files saved in their own directory:
+ `active_unfollowers`:
+ Will store only the unfollowers WHOM you are currently following.
+ Its files will be saved at **logs folder**, `~/InstaPy/logs/YourOwnUsername/relationship_data/Bernard_bear/unfollowers/active_unfollowers/` directory.

Sample **filename** `03-06-2018~all~75.json`:
+ `03-06-2018` means the **time** of the data acquisition.
+ `"all"` means that it is all of the unfollowers data;
Expand Down Expand Up @@ -1017,7 +1027,7 @@ There are **several** `use cases` of this tool for **various purposes**.

#now Scooby Doo will tell his friend Shaggy about this, who knows, maybe Shaggy will unfollow them all or even add to block :D
```



### Pick Fans of a user
Expand Down
27 changes: 24 additions & 3 deletions instapy/instapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __init__(self,
self.smart_hashtags = []

self.dont_like = ['sex', 'nsfw']
self.mandatory_words = []
self.ignore_if_contains = []
self.ignore_users = []

Expand Down Expand Up @@ -430,6 +431,21 @@ def set_dont_like(self, tags=None):

return self

def set_mandatory_words(self, tags=None):
"""Changes the possible restriction tags, if all of this
hashtags is in the description, the image will be liked"""
if self.aborting:
return self

if not isinstance(tags, list):
self.logger.warning('Unable to use your set_mandatory_words '
'configuration!')
self.aborting = True

self.mandatory_words = tags or []

return self

def set_user_interact(self,
amount=10,
percentage=100,
Expand Down Expand Up @@ -843,6 +859,7 @@ def like_by_locations(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -1019,6 +1036,7 @@ def comment_by_locations(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -1196,6 +1214,7 @@ def like_by_tags(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -1435,6 +1454,7 @@ def like_by_users(self, usernames, amount=10, randomize=False, media=None):
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -1610,6 +1630,7 @@ def interact_by_users(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -2375,6 +2396,7 @@ def like_by_feed_generator(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -2783,6 +2805,7 @@ def follow_by_tags(self,
check_link(self.browser,
link,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -2871,6 +2894,7 @@ def interact_by_URL(self,
check_link(self.browser,
url,
self.dont_like,
self.mandatory_words,
self.ignore_if_contains,
self.logger)
)
Expand Down Expand Up @@ -3016,6 +3040,3 @@ def interact_by_URL(self,
self.not_valid_users += not_valid_users

return self



6 changes: 5 additions & 1 deletion instapy/like_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,14 @@ def get_links_for_username(browser,



def check_link(browser, post_link, dont_like, ignore_if_contains, logger):
def check_link(browser, post_link, dont_like, mandatory_words, ignore_if_contains, logger):
"""
Check the given link if it is appropriate
:param browser: The selenium webdriver instance
:param link:
:param dont_like: hashtags of inappropriate phrases
:param mandatory_words: words of appropriate phrases
:param ignore_if_contains:
:param logger: the logger instance
Expand Down Expand Up @@ -475,6 +476,9 @@ def check_link(browser, post_link, dont_like, ignore_if_contains, logger):
logger.info('Link: {}'.format(post_link.encode('utf-8')))
logger.info('Description: {}'.format(image_text.encode('utf-8')))

if mandatory_words :
if not all((word in image_text for word in mandatory_words)) :
return True, user_name, is_video, 'Mandatory words not fulfilled', "Not mandatory likes"

if any((word in image_text for word in ignore_if_contains)):
return False, user_name, is_video, 'None', "Pass"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_like_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def test_inappropriate_text_on_dont_like(self, sleep):
[{'media': {'is_video': False, 'owner': {'username': 'john'}, 'caption': '#f\xf6o'}}],
'']
inappropriate, user_name, is_video, reason = check_link(
browser, MagicMock(), ['#f'], MagicMock(), MagicMock(), MagicMock(),
browser, MagicMock(), ['#f'], [], MagicMock(), MagicMock(), MagicMock(),
None, None, MagicMock())
assert inappropriate is True

0 comments on commit 1645d61

Please sign in to comment.