implement extractor.wait()

This commit is contained in:
Mike Fährmann
2020-01-04 23:21:45 +01:00
parent 5532e9c158
commit 569747a78d
3 changed files with 28 additions and 21 deletions

View File

@@ -122,6 +122,23 @@ class Extractor():
raise exception.HttpError(msg)
def wait(self, *, seconds=None, until=None, reason=None, adjust=1):
now = datetime.datetime.now()
if seconds:
seconds = float(seconds)
until = now + datetime.timedelta(seconds=seconds)
elif until:
until = datetime.datetime.fromtimestamp(float(until))
seconds = (until - now).total_seconds()
else:
raise ValueError("Either 'seconds' or 'until' is required")
if reason:
isotime = until.time().isoformat("seconds")
self.log.info("Waiting until %s for %s.", isotime, reason)
time.sleep(seconds + adjust)
def _get_auth_info(self):
"""Return authentication information as (username, password) tuple"""
username = self.config("username")