Skip to content

Commit

Permalink
Merge pull request #75 from LRWeber/countdown-cleanup
Browse files Browse the repository at this point in the history
Simplified GitHub scraper wait countdown.
  • Loading branch information
IanLee1521 authored Sep 7, 2023
2 parents 95d721b + 40e6c51 commit f00ea1b
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions scraper/github/queryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def queryGitHub(

self._countdown(
self.retryDelay,
printString="Query accepted but not yet processed. Trying again in %*dsec...",
printString="Query accepted but not yet processed. Trying again in %*d seconds...",
verbose=(verbosity >= 0),
)
return self.queryGitHub(
Expand Down Expand Up @@ -347,7 +347,7 @@ def queryGitHub(

self._countdown(
self.retryDelay,
printString="Server error. Trying again in %*dsec...",
printString="Server error. Trying again in %*d seconds...",
verbose=(verbosity >= 0),
)
return self.queryGitHub(
Expand Down Expand Up @@ -392,7 +392,7 @@ def queryGitHub(
)
self._countdown(
self.retryDelay,
printString="Unknown API error. Trying again in %*dsec...",
printString="Unknown API error. Trying again in %*d seconds...",
verbose=(verbosity >= 0),
)
return self.queryGitHub(
Expand Down Expand Up @@ -571,31 +571,20 @@ def _awaitReset(self, utcTimeStamp, verbose=True):
def _countdown(
self, waitTime=0, printString="Waiting %*d seconds...", verbose=True
):
"""Makes a pretty countdown.
"""Prints a message and waits.
Args:
gitquery (str): The query or endpoint itself.
Examples:
query: 'query { viewer { login } }'
endpoint: '/user'
waitTime (Optional[int]): Number of seconds to wait. Defaults to 0.
printString (Optional[str]): A counter message to display.
Defaults to 'Waiting %*d seconds...'
Defaults to "Waiting %*d seconds...".
verbose (Optional[bool]): If False, all extra printouts will be
suppressed. Defaults to True.
"""
if waitTime <= 0:
waitTime = self.retryDelay
for remaining in range(waitTime, 0, -1):
_vPrint(
verbose,
"\r" + printString % (len(str(waitTime)), remaining),
end="",
flush=True,
)
time.sleep(1)
if verbose:
_vPrint(verbose, "\r" + printString % (len(str(waitTime)), 0))
_vPrint(verbose, printString % (len(str(waitTime)), waitTime))
time.sleep(waitTime)


class DataManager:
Expand Down

0 comments on commit f00ea1b

Please sign in to comment.