Skip to content

Commit

Permalink
fix download error
Browse files Browse the repository at this point in the history
  • Loading branch information
MeetWq committed Mar 11, 2023
1 parent 2cc8874 commit 4c03d1f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions meme_generator/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,22 @@
from .version import __version__


async def _download(
client: httpx.AsyncClient,
url: str,
semaphore: asyncio.Semaphore = asyncio.Semaphore(10),
):
async with semaphore:
try:
resp = await client.get(url, timeout=20, follow_redirects=True)
resp.raise_for_status()
return resp.content
except httpx.HTTPError as e:
logger.warning(f"{url} download failed!\n{e}")


def _resource_url(path: str) -> str:
return f"{meme_config.resource.resource_url}/blob/v{__version__}/{path}"


async def check_resources():
semaphore = asyncio.Semaphore(10)

async def _download(client: httpx.AsyncClient, url: str):
async with semaphore:
try:
resp = await client.get(url, timeout=20, follow_redirects=True)
resp.raise_for_status()
return resp.content
except httpx.HTTPError as e:
logger.warning(f"{url} download failed!\n{e}")

async with httpx.AsyncClient() as client:
if content := await _download(
client, _resource_url("resources/resource_list.json")
Expand Down
2 changes: 1 addition & 1 deletion meme_generator/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.3"
__version__ = "0.0.4"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "meme-generator"
version = "0.0.3"
version = "0.0.4"
description = "Python package for making fun pictures"
authors = ["meetwq <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 4c03d1f

Please sign in to comment.