Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified GitHub scraper wait countdown. #75

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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