Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions pysus/api/ducklake/catalog/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ async def _download_catalog(
force: bool = False,
callback: Callable[[int, int], None] | None = None,
) -> None:
url = f"https://{types.S3_ENDPOINT}/{types.S3_BUCKET}/{remote_path}"
remote = str(remote_path).replace("\\", "/")
url = f"https://{types.S3_ENDPOINT}/{types.S3_BUCKET}/{remote}"

if local_path.exists() and not force:
try:
Expand All @@ -170,7 +171,17 @@ async def _download_catalog(

remote_size = 0
if local_size != -1:
async with httpx.AsyncClient(follow_redirects=True) as client:
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/120.0.0.0 Safari/537.36"
),
"Referer": "https://github.com/AlertaDengue/PySUS",
}
async with httpx.AsyncClient(
headers=headers, follow_redirects=True
) as client:
try:
head = await client.head(url)

Expand All @@ -189,7 +200,7 @@ async def _download_catalog(

try:
await download_http(
remote_path=remote_path,
remote_path=remote,
local_path=local_path,
callback=callback,
)
Expand Down
10 changes: 10 additions & 0 deletions pysus/api/ducklake/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ async def download_http(
local_path: Path,
callback: Callable[[int, int], None] | None = None,
) -> None:
remote_path = str(remote_path).replace("\\", "/")
url = f"https://{types.S3_ENDPOINT}/{types.S3_BUCKET}/{remote_path}"
max_retries = 5

timeout = httpx.Timeout(15.0, read=60.0, write=20.0, connect=15.0)
limits = httpx.Limits(max_keepalive_connections=5, max_connections=10)
headers = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/120.0.0.0 Safari/537.36"
),
"Referer": "https://github.com/AlertaDengue/PySUS",
}

for attempt in range(max_retries):
try:
async with httpx.AsyncClient(
headers=headers,
follow_redirects=True,
verify=False,
limits=limits,
Expand Down
Loading