@@ -6472,6 +6472,9 @@ Description
|
|||||||
|
|
||||||
``"abort"``
|
``"abort"``
|
||||||
Raise an error and stop extraction
|
Raise an error and stop extraction
|
||||||
|
``"abort:N"``
|
||||||
|
Raise an error and stop extraction
|
||||||
|
after waiting ``N`` times until rate limit reset
|
||||||
``"wait"``
|
``"wait"``
|
||||||
Wait until rate limit reset
|
Wait until rate limit reset
|
||||||
``"wait:N"``
|
``"wait:N"``
|
||||||
|
|||||||
@@ -2246,12 +2246,26 @@ class TwitterAPI():
|
|||||||
rl = self.extractor.config("ratelimit")
|
rl = self.extractor.config("ratelimit")
|
||||||
if rl == "abort":
|
if rl == "abort":
|
||||||
raise exception.AbortExtraction("Rate limit exceeded")
|
raise exception.AbortExtraction("Rate limit exceeded")
|
||||||
elif rl and isinstance(rl, str) and rl.startswith("wait:"):
|
|
||||||
until = None
|
until = response.headers.get("x-rate-limit-reset")
|
||||||
seconds = text.parse_float(rl.partition(":")[2]) or 60.0
|
seconds = None if until else 60.0
|
||||||
else:
|
|
||||||
until = response.headers.get("x-rate-limit-reset")
|
if rl and isinstance(rl, str) and ":" in rl:
|
||||||
seconds = None if until else 60.0
|
rl, _, num = rl.partition(":")
|
||||||
|
if rl == "abort":
|
||||||
|
amt = getattr(self, "_ratelimit_amt", 1)
|
||||||
|
num = text.parse_int(num)
|
||||||
|
msg = f"Rate limit exceeded ({amt}/{num})"
|
||||||
|
if amt >= num:
|
||||||
|
raise exception.AbortExtraction(msg)
|
||||||
|
self.log.warning(msg)
|
||||||
|
self._ratelimit_amt = amt + 1
|
||||||
|
elif rl == "wait":
|
||||||
|
until = None
|
||||||
|
seconds = text.parse_float(num) or 60.0
|
||||||
|
else:
|
||||||
|
self.log.warning("Unsupported 'ratelimit' setting '%s'", rl)
|
||||||
|
|
||||||
self.extractor.wait(until=until, seconds=seconds)
|
self.extractor.wait(until=until, seconds=seconds)
|
||||||
|
|
||||||
def _process_tombstone(self, entry, tombstone):
|
def _process_tombstone(self, entry, tombstone):
|
||||||
|
|||||||
Reference in New Issue
Block a user