From: Josemando Sobral Date: Sun, 2 Feb 2025 21:48:34 +0000 (-0300) Subject: adding rate limit X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=8a584885736fc66a37514a08bb6450be6767d016;p=gamesguru%2Fgetmyancestors.git adding rate limit ORIGINAL COMMIT ~~~~~~~~~~~~~~~ $ git show f6bb22e --stat commit f6bb22e6c3602d30e55fc9eeb140b964552b8d18 Author: Josemando Sobral Date: Sun Feb 2 18:48:34 2025 -0300 adding rate limit getmyancestors/classes/session.py | 8 ++++++++ pyproject.toml | 2 +- requirements.txt | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) Signed-off-by: Shane Jaroch --- diff --git a/getmyancestors/classes/session.py b/getmyancestors/classes/session.py index 9f9aeca..30ed47a 100644 --- a/getmyancestors/classes/session.py +++ b/getmyancestors/classes/session.py @@ -7,6 +7,8 @@ import requests from requests_cache import CachedSession as CSession from fake_useragent import UserAgent +from requests_ratelimiter import LimiterAdapter + # local imports from getmyancestors.classes.translation import translations @@ -31,6 +33,12 @@ class GMASession: self.fid = self.lang = self.display_name = None self.counter = 0 self.headers = {"User-Agent": UserAgent().firefox} + + # Apply a rate-limit (5 requests per second) to all requests + adapter = LimiterAdapter(per_second=5) + self.mount('http://', adapter) + self.mount('https://', adapter) + self.login() @property diff --git a/pyproject.toml b/pyproject.toml index 094f077..58e1571 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,10 +16,11 @@ classifiers = [ "Programming Language :: Python :: 3 :: Only", ] dependencies = [ - "babelfish==0.6.0", - "diskcache==5.2.1", - "requests==2.25.1", - "fake-useragent==1.2.1", + "babelfish==0.6.1", + "diskcache==5.6.3", + "requests==2.32.3", + "fake-useragent==2.0.3", + "requests-ratelimiter==0.7.0" ] dynamic = ["version", "readme"] @@ -37,4 +38,3 @@ getmyancestors = ["fstogedcom.png"] getmyancestors = "getmyancestors.getmyancestors:main" mergemyancestors = "getmyancestors.mergemyancestors:main" fstogedcom = "getmyancestors.fstogedcom:main" - diff --git a/requirements.txt b/requirements.txt index c2d23a8..471fa90 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -babelfish==0.6.0 -diskcache==5.2.1 -requests==2.31.0 -fake-useragent==1.2.1 -setuptools==70.1.0 \ No newline at end of file +babelfish==0.6.1 +diskcache==5.6.3 +requests==2.32.3 +fake-useragent==2.0.3 +requests-ratelimiter==0.7.0 +setuptools==70.1.0