Skip to content

Commit dbb4df1

Browse files
schealexelulcao
andauthored
Fix user following (InstaPy#6204)
* Fix user following * reformat unfollow_util * Fix formatting so travis stops complaining * reformat proxy_extension.py * Changes requested by review * Remove unused import * Update CHANGELOG.md Bumped version for the PR commit, UNRELEASED Co-authored-by: Daniel Carvallo <[email protected]>
1 parent 78ad421 commit dbb4df1

19 files changed

+142
-121
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ The **goal** of this file is explaining to the users of our project the notable
55
_The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)_
66

77

8+
## [0.6.16] - UNRELEASED
9+
10+
### Added
11+
12+
- Fix user following and verification of follow
13+
814
## [0.6.15] - UNRELEASED
15+
916
### Added
1017

1118
- Added `verified_only` argument to `get_followers` to return only verified users

instapy/browser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def set_selenium_local_session(
158158

159159

160160
def proxy_authentication(browser, logger, proxy_username, proxy_password):
161-
""" Authenticate proxy using popup alert window """
161+
"""Authenticate proxy using popup alert window"""
162162

163163
# FIXME: https://github.com/SeleniumHQ/selenium/issues/7239
164164
# this feauture is not working anymore due to the Selenium bug report above
@@ -273,10 +273,10 @@ def wrapper(*args, **kwargs):
273273

274274

275275
class custom_browser(Remote):
276-
""" Custom browser instance for manupulation later on """
276+
"""Custom browser instance for manupulation later on"""
277277

278278
def find_element_by_xpath(self, *args, **kwargs):
279-
""" example usage of hooking into built in functions """
279+
"""example usage of hooking into built in functions"""
280280
rv = super(custom_browser, self).find_element_by_xpath(*args, **kwargs)
281281
return rv
282282

@@ -312,6 +312,6 @@ def wait_for_valid_authorization(self, username, logger):
312312

313313

314314
def convert_selenium_browser(driver):
315-
""" Changed the class to our custom class """
315+
"""Changed the class to our custom class"""
316316
driver.__class__ = custom_browser
317317
return driver

instapy/clarifai_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def check_image(
102102

103103

104104
def given_tags_in_result(search_tags, clarifai_tags, full_match=False):
105-
"""Checks the clarifai tags if it contains one (or all) search tags """
105+
"""Checks the clarifai tags if it contains one (or all) search tags"""
106106
if full_match:
107107
return all([tag in clarifai_tags for tag in search_tags])
108108
else:

instapy/comment_util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def verify_mandatory_words(
236236
def get_comments_on_post(
237237
browser, owner, poster, amount, post_link, ignore_users, randomize, logger
238238
):
239-
""" Fetch comments data on posts """
239+
"""Fetch comments data on posts"""
240240
web_address_navigator(browser, post_link)
241241

242242
comments = []
@@ -333,7 +333,7 @@ def get_comments_on_post(
333333

334334

335335
def is_commenting_enabled(browser, logger):
336-
""" Find out if commenting on the post is enabled """
336+
"""Find out if commenting on the post is enabled"""
337337

338338
try:
339339
comments_disabled = browser.execute_script(
@@ -365,7 +365,7 @@ def is_commenting_enabled(browser, logger):
365365

366366

367367
def get_comments_count(browser, logger):
368-
""" Get the number of total comments in the post """
368+
"""Get the number of total comments in the post"""
369369
try:
370370
comments_count = browser.execute_script(
371371
"return window.__additionalData[Object.keys(window.__additionalData)[0]].data"
@@ -380,7 +380,7 @@ def get_comments_count(browser, logger):
380380

381381

382382
def verify_commented_image(browser, link, owner, logger):
383-
""" Fetch comments data on posts to determine if already commented """
383+
"""Fetch comments data on posts to determine if already commented"""
384384

385385
web_address_navigator(browser, link)
386386

instapy/commenters_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def users_liked(browser, photo_url, amount=100, logger=None):
316316

317317

318318
def likers_from_photo(browser, amount=20, logger=None):
319-
""" Get the list of users from the 'Likes' dialog of a photo """
319+
"""Get the list of users from the 'Likes' dialog of a photo"""
320320

321321
try:
322322
if check_exists_by_xpath(

instapy/file_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def use_assets():
2828

2929

3030
def get_workspace():
31-
""" Make a workspace ready for user """
31+
"""Make a workspace ready for user"""
3232

3333
if WORKSPACE["path"]:
3434
workspace = verify_workspace_name(WORKSPACE["path"])
@@ -47,7 +47,7 @@ def get_workspace():
4747

4848

4949
def set_workspace(path=None):
50-
""" Set a custom workspace for use """
50+
"""Set a custom workspace for use"""
5151

5252
if not Settings.InstaPy_is_running:
5353
if path:
@@ -92,15 +92,15 @@ def set_workspace(path=None):
9292

9393

9494
def update_workspace(latest_path):
95-
""" Update the workspace constant with its latest path """
95+
"""Update the workspace constant with its latest path"""
9696

9797
latest_path = slashen(latest_path, "native")
9898
validate_path(latest_path)
9999
WORKSPACE.update(path=latest_path)
100100

101101

102102
def move_workspace(old_path, new_path):
103-
""" Find data files in old workspace folder and move to new location """
103+
"""Find data files in old workspace folder and move to new location"""
104104
# write in future
105105

106106

@@ -121,7 +121,7 @@ def update_locations():
121121

122122

123123
def get_home_path():
124-
""" Get user's home directory """
124+
"""Get user's home directory"""
125125

126126
if python_version() >= "3.5":
127127
from pathlib import Path
@@ -137,7 +137,7 @@ def get_home_path():
137137

138138

139139
def slashen(path, direction="forward"):
140-
""" Replace backslashes in paths with forward slashes """
140+
"""Replace backslashes in paths with forward slashes"""
141141

142142
if direction == "forward":
143143
path = path.replace("\\", "/")
@@ -153,7 +153,7 @@ def slashen(path, direction="forward"):
153153

154154

155155
def remove_last_slash(path):
156-
""" Remove the last slash in the given path [if any] """
156+
"""Remove the last slash in the given path [if any]"""
157157

158158
if path.endswith("/"):
159159
path = path[:-1]
@@ -162,7 +162,7 @@ def remove_last_slash(path):
162162

163163

164164
def verify_workspace_name(path):
165-
""" Make sure chosen workspace name is InstaPy friendly """
165+
"""Make sure chosen workspace name is InstaPy friendly"""
166166

167167
path = slashen(path)
168168
path = remove_last_slash(path)
@@ -182,7 +182,7 @@ def verify_workspace_name(path):
182182

183183

184184
def differ_paths(old, new):
185-
""" Compare old and new paths """
185+
"""Compare old and new paths"""
186186

187187
if old and old.endswith(("\\", "/")):
188188
old = old[:-1]
@@ -196,7 +196,7 @@ def differ_paths(old, new):
196196

197197

198198
def validate_path(path):
199-
""" Make sure the given path exists """
199+
"""Make sure the given path exists"""
200200

201201
if not path_exists(path):
202202
try:

instapy/follow_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
def get_following_status(
2020
browser, track, username, person, person_id, logger, logfolder
2121
):
22-
""" Verify if you are following the user in the loaded page """
22+
"""Verify if you are following the user in the loaded page"""
2323
if person == username:
2424
return "OWNER", None
2525

instapy/instapy.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def set_action_delays(
491491
random_range_to: int = None,
492492
safety_match: bool = True,
493493
):
494-
""" Set custom sleep delay after actions """
494+
"""Set custom sleep delay after actions"""
495495
Settings.action_delays.update(
496496
{
497497
"enabled": enabled,
@@ -902,7 +902,7 @@ def follow_commenters(
902902
sleep_delay: int = 600,
903903
interact: bool = False,
904904
):
905-
""" Follows users' commenters """
905+
"""Follows users' commenters"""
906906

907907
if self.aborting:
908908
return self
@@ -1022,7 +1022,7 @@ def follow_likers(
10221022
sleep_delay: int = 600,
10231023
interact: bool = False,
10241024
):
1025-
""" Follows users' likers """
1025+
"""Follows users' likers"""
10261026
if self.aborting:
10271027
return self
10281028

@@ -1344,7 +1344,7 @@ def set_relationship_bounds(
13441344
self.max_posts = max_posts if enabled is True else None
13451345

13461346
def validate_user_call(self, user_name: str):
1347-
""" Short call of validate_username() function """
1347+
"""Short call of validate_username() function"""
13481348
validation, details = validate_username(
13491349
self.browser,
13501350
user_name,
@@ -1451,7 +1451,7 @@ def set_delimit_commenting(
14511451
self.comments_mandatory_words = comments_mandatory_words
14521452

14531453
def set_simulation(self, enabled: bool = True, percentage: int = 100):
1454-
""" Sets aside simulation parameters """
1454+
"""Sets aside simulation parameters"""
14551455
if enabled not in [True, False]:
14561456
self.logger.info(
14571457
"Invalid simulation parameter! Please use correct syntax "
@@ -3629,7 +3629,7 @@ def follow_user_followers(
36293629
interact: bool = False,
36303630
sleep_delay: int = 600,
36313631
):
3632-
""" Follow the `Followers` of given users """
3632+
"""Follow the `Followers` of given users"""
36333633
if self.aborting:
36343634
return self
36353635

@@ -3817,7 +3817,7 @@ def follow_user_following(
38173817
interact: bool = False,
38183818
sleep_delay: int = 600,
38193819
):
3820-
""" Follow the `Following` of given users """
3820+
"""Follow the `Following` of given users"""
38213821
if self.aborting:
38223822
return self
38233823

@@ -4627,7 +4627,7 @@ def pick_unfollowers(
46274627
def pick_nonfollowers(
46284628
self, username: str = None, live_match: bool = False, store_locally: bool = True
46294629
):
4630-
""" Returns Nonfollowers data of a given user """
4630+
"""Returns Nonfollowers data of a given user"""
46314631

46324632
message = "Starting to pick Nonfollowers of {}..".format(username)
46334633
highlight_print(self.username, message, "feature", "info", self.logger)
@@ -4989,7 +4989,7 @@ def follow_by_tags(
49894989
def interact_by_URL(
49904990
self, urls: list = [], randomize: bool = False, interact: bool = False
49914991
):
4992-
""" Interact on posts at given URLs """
4992+
"""Interact on posts at given URLs"""
49934993

49944994
if self.aborting:
49954995
return self
@@ -5284,7 +5284,7 @@ def feature_in_feature(self, feature, validate_users):
52845284
self.internal_usage.pop(feature)
52855285

52865286
def live_report(self):
5287-
""" Report live sessional statistics """
5287+
"""Report live sessional statistics"""
52885288

52895289
print("")
52905290

@@ -5356,15 +5356,15 @@ def live_report(self):
53565356
)
53575357

53585358
def set_do_reply_to_comments(self, enabled: bool = False, percentage: int = 0):
5359-
""" Define if the comments on posts should be replied """
5359+
"""Define if the comments on posts should be replied"""
53605360

53615361
self.do_reply_to_comments = enabled
53625362
self.reply_to_comments_percent = percentage
53635363

53645364
return self
53655365

53665366
def set_comment_replies(self, replies: list = [], media: str = None):
5367-
""" Set the replies to comments """
5367+
"""Set the replies to comments"""
53685368

53695369
if not replies:
53705370
self.logger.info("Please, provide some comment replies for use next time.")
@@ -5395,7 +5395,7 @@ def set_use_meaningcloud(
53955395
subjectivity: str = None,
53965396
confidence: bool = 100,
53975397
):
5398-
""" Set MeaningCloud Sentiment Analysis API configuration """
5398+
"""Set MeaningCloud Sentiment Analysis API configuration"""
53995399

54005400
if license_key is None:
54015401
license_key = os.environ.get("MEANINGCLOUD_LIC_KEY")
@@ -5430,7 +5430,7 @@ def set_use_yandex(
54305430
match_language: bool = False,
54315431
language_code: str = "en",
54325432
):
5433-
""" Set Yandex Translate API configuration """
5433+
"""Set Yandex Translate API configuration"""
54345434

54355435
if API_key is None:
54365436
API_key = os.environ.get("YANDEX_API_KEY")
@@ -5838,7 +5838,7 @@ def is_mandatory_character(self, uchr):
58385838
)
58395839

58405840
def run_time(self):
5841-
""" Get the time session lasted in seconds """
5841+
"""Get the time session lasted in seconds"""
58425842

58435843
real_time = time.time()
58445844
run_time = real_time - self.start_time
@@ -5895,7 +5895,7 @@ def accept_follow_requests(self, amount: int = 100, sleep_delay: int = 1):
58955895
return self
58965896

58975897
def join_pods(self, topic: str = "general", engagement_mode: str = "normal"):
5898-
""" Join pods """
5898+
"""Join pods"""
58995899
if topic not in self.allowed_pod_topics:
59005900
self.logger.error(
59015901
"You have entered an invalid topic for pods, allowed topics are : {}. Exiting...".format(
@@ -6091,7 +6091,7 @@ def engage_with_posts(self, pod_posts, modespecific_comment_percentage):
60916091
self.logger.error("Failed for {} with Error {}".format(pod_post, err))
60926092

60936093
def story_by_tags(self, tags: list = None):
6094-
""" Watch stories for specific tag(s) """
6094+
"""Watch stories for specific tag(s)"""
60956095
if self.aborting:
60966096
return self
60976097

@@ -6123,7 +6123,7 @@ def story_by_tags(self, tags: list = None):
61236123
self.reels_watched += reels
61246124

61256125
def story_by_users(self, users: list = None):
6126-
""" Watch stories for specific user(s)"""
6126+
"""Watch stories for specific user(s)"""
61276127
if self.aborting:
61286128
return self
61296129

@@ -6155,7 +6155,7 @@ def story_by_users(self, users: list = None):
61556155
self.reels_watched += reels
61566156

61576157
def target_list(self, file):
6158-
""" Extracts target list from text file """
6158+
"""Extracts target list from text file"""
61596159
target_list = file_handling(file)
61606160

61616161
if "FileNotFoundError" in target_list:

instapy/like_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ def verify_liking(browser, maximum, minimum, logger):
982982

983983

984984
def like_comment(browser, original_comment_text, logger):
985-
""" Like the given comment """
985+
"""Like the given comment"""
986986
comments_block_XPath = read_xpath(
987987
like_comment.__name__, "comments_block"
988988
) # quite an efficient

0 commit comments

Comments
 (0)