Skip to content

Commit

Permalink
Improve setting requests delay
Browse files Browse the repository at this point in the history
  • Loading branch information
thalida committed Sep 1, 2024
1 parent a461e2f commit 867a32a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions ao3_sync/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AO3ApiClient(BaseSettings):
username (str): AO3 username
password (SecretStr): AO3 password
host (str): AO3 host
num_requests_per_second (float | int): Number of requests per second
requests_delay_seconds (float | int): Delay between requests
output_dir (str): Output directory
downloads_dir (str): Downloads directory
use_history (bool): Use history
Expand All @@ -69,7 +69,7 @@ class AO3ApiClient(BaseSettings):
output_dir: str = "output/"

downloads_dir: str = "downloads/"
num_requests_per_second: float | int = 0.2
requests_delay_seconds: float = 4.0

use_history: bool = False
history_filepath: str = "history.json"
Expand All @@ -83,7 +83,7 @@ class AO3ApiClient(BaseSettings):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self._http_client = AO3LimiterSession(per_second=self.num_requests_per_second)
self._http_client = AO3LimiterSession(burst=1, per_second=1 / self.requests_delay_seconds)
self._http_client.headers.update(
{"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:127.0) Gecko/20100101 Firefox/127.0"}
)
Expand Down
14 changes: 7 additions & 7 deletions ao3_sync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def create_option_group(options):
"options": [
"--output-dir",
"--downloads-dir",
"--requests-per-second",
"--requests-delay-seconds",
"--history",
"--history-file",
],
Expand Down Expand Up @@ -147,10 +147,10 @@ def api_command(func):
help="Directory to save downloads. Directory wil be nested under output-dir",
)
@click.option(
"--requests-per-second",
"num_requests_per_second",
"--requests-delay-seconds",
"requests_delay_seconds",
type=float,
default=base_api.num_requests_per_second,
default=base_api.requests_delay_seconds,
show_default=True,
help="Number of requests per second",
)
Expand Down Expand Up @@ -198,7 +198,7 @@ def wrapper(ctx, **kwargs):
password=kwargs.pop("password"),
output_dir=kwargs.pop("output_dir"),
downloads_dir=kwargs.pop("downloads_dir"),
num_requests_per_second=kwargs.pop("num_requests_per_second"),
requests_delay_seconds=kwargs.pop("requests_delay_seconds"),
use_history=kwargs.pop("use_history"),
history_filepath=kwargs.pop("history_filepath"),
debug=kwargs.pop("debug"),
Expand Down Expand Up @@ -226,8 +226,8 @@ def wrapper(ctx, **kwargs):
table.add_column("Value")
table.add_row("Downloads Directory", str(api.get_downloads_dir().resolve()), end_section=True)

if api.num_requests_per_second != base_api.num_requests_per_second:
table.add_row("Requests Per Second", f"{api.num_requests_per_second}", end_section=True)
if api.requests_delay_seconds != base_api.requests_delay_seconds:
table.add_row("Requests Delay (seconds)", str(api.requests_delay_seconds), end_section=True)

if api.use_history:
table.add_row("History", "[green]Enabled")
Expand Down

0 comments on commit 867a32a

Please sign in to comment.