Skip to content

Commit

Permalink
Run with retries (#7)
Browse files Browse the repository at this point in the history
* get own profile with retries

* add docstring
  • Loading branch information
isaac-chung committed Apr 27, 2023
1 parent 40d07ef commit 513f8f2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion give_kudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@ def email_login(self):
self.page.fill("#password", self.PASSWORD)
self.page.click("button[type='submit']")
print("---Logged in!!---")
# limit activities count by GET parameter
self._run_with_retries(func=self._get_page_and_own_profile)

def _run_with_retries(self, func, retries=3):
"""
Retry logic with sleep in between tries.
"""
for i in range(retries):
if i == retries - 1:
raise Exception(f"Retries {retries} times failed.")
try:
func()
return
except:
time.sleep(1)

def _get_page_and_own_profile(self):
"""
Limit activities count by GET parameter and get own profile ID.
"""
self.page.goto(os.path.join(BASE_URL, f"dashboard?num_entries={self.num_entries}"), wait_until="networkidle")
self.own_profile_id = self.page.locator("#athlete-profile .card-body > a").get_attribute('href').split("/athletes/")[1]

Expand Down

0 comments on commit 513f8f2

Please sign in to comment.