[reactor] add wait-min & -max options (#148)

server
Mike Fährmann 6 years ago
parent 8e01cf0ef8
commit e95b24f056
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -583,6 +583,16 @@ Description Download Pixiv's Ugoira animations or ignore them.
=========== ===== =========== =====
extractor.reactor.wait-min & .wait-max
--------------------------------------
=========== =====
Type ``float``
Default ``3.0`` and ``6.0``
Description Minimum and maximum wait time in seconds between HTTP requests
during the extraction process.
=========== =====
extractor.recursive.blacklist extractor.recursive.blacklist
----------------------------- -----------------------------
=========== ===== =========== =====

@ -11,6 +11,8 @@
from .common import SharedConfigExtractor, Message from .common import SharedConfigExtractor, Message
from .. import text from .. import text
import urllib.parse import urllib.parse
import random
import time
import json import json
@ -30,6 +32,11 @@ class ReactorExtractor(SharedConfigExtractor):
self.root = "http://" + match.group(1) self.root = "http://" + match.group(1)
self.session.headers["Referer"] = self.root self.session.headers["Referer"] = self.root
self.wait_min = self.config("wait-min", 3)
self.wait_max = self.config("wait-max", 6)
if self.wait_max < self.wait_min:
self.wait_max = self.wait_min
if not self.category: if not self.category:
# set category based on domain name # set category based on domain name
netloc = urllib.parse.urlsplit(self.root).netloc netloc = urllib.parse.urlsplit(self.root).netloc
@ -55,6 +62,7 @@ class ReactorExtractor(SharedConfigExtractor):
def _pagination(self, url): def _pagination(self, url):
while True: while True:
time.sleep(random.uniform(self.wait_min, self.wait_max))
page = self.request(url).text page = self.request(url).text
yield from text.extract_iter( yield from text.extract_iter(

Loading…
Cancel
Save