Skip to content

Commit

Permalink
twitch user image download should be async (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed May 13, 2023
1 parent 65f0960 commit 07a1763
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions nowplaying/twitch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import time
import traceback

import requests

from twitchAPI.twitch import Twitch
from twitchAPI.helper import first
from twitchAPI.types import AuthScope
Expand Down
5 changes: 3 additions & 2 deletions nowplaying/twitch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async def get_user_image(twitch, loginname):
image = None
try:
user = await first(twitch.get_users(logins=loginname))
req = requests.get(user.profile_image_url, timeout=5)
image = nowplaying.utils.image2png(req.content)
async with aiohttp.ClientSession() as session:
async with session.get(user.profile_image_url, timeout=5) as resp:
image = nowplaying.utils.image2png(await resp.read())
except Exception as error: #pylint: disable=broad-except
logging.error(error)
return image
Expand Down

0 comments on commit 07a1763

Please sign in to comment.