MCPcopy
hub / github.com/InstaPy/InstaPy / web_address_navigator

Function web_address_navigator

instapy/util.py:1291–1331  ·  view source on GitHub ↗

Checks and compares current URL of web page and the URL to be navigated and if it is different, it does navigate

(browser, link)

Source from the content-addressed store, hash-verified

1289
1290
1291def web_address_navigator(browser, link):
1292 """Checks and compares current URL of web page and the URL to be
1293 navigated and if it is different, it does navigate"""
1294 current_url = get_current_url(browser)
1295 total_timeouts = 0
1296 page_type = None # file or directory
1297
1298 # remove slashes at the end to compare efficiently
1299 if current_url is not None and current_url.endswith("/"):
1300 current_url = current_url[:-1]
1301
1302 if link.endswith("/"):
1303 link = link[:-1]
1304 page_type = "dir" # slash at the end is a directory
1305
1306 new_navigation = current_url != link
1307
1308 if current_url is None or new_navigation:
1309 link = link + "/" if page_type == "dir" else link # directory links
1310 # navigate faster
1311
1312 while True:
1313 try:
1314 browser.get(link)
1315 # update server calls
1316 update_activity(browser, state=None)
1317 sleep(2)
1318 break
1319
1320 except TimeoutException as exc:
1321 if total_timeouts >= 7:
1322 raise TimeoutException(
1323 "Retried {} times to GET '{}' webpage "
1324 "but failed out of a timeout!\n\t{}".format(
1325 total_timeouts,
1326 str(link).encode("utf-8"),
1327 str(exc).encode("utf-8"),
1328 )
1329 )
1330 total_timeouts += 1
1331 sleep(2)
1332
1333
1334@contextmanager

Callers 15

unfollowFunction · 0.85
follow_userFunction · 0.85
get_given_user_followersFunction · 0.85
get_given_user_followingFunction · 0.85
unfollow_userFunction · 0.85
verify_actionFunction · 0.85
get_follow_requestsFunction · 0.85
log_follower_numFunction · 0.85
log_following_numFunction · 0.85
get_comments_on_postFunction · 0.85
verify_commented_imageFunction · 0.85

Calls 3

get_current_urlFunction · 0.85
update_activityFunction · 0.85
sleepFunction · 0.85

Tested by

no test coverage detected