21 lines
564 B
Python
21 lines
564 B
Python
import asyncio
|
|
import base64
|
|
from typing import List, Tuple
|
|
|
|
import aiohttp
|
|
|
|
|
|
async def fetch_image(url: str) -> str:
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.get(url) as response:
|
|
if response.status == 200:
|
|
image_data = await response.read()
|
|
return base64.b64encode(image_data).decode("utf-8")
|
|
else:
|
|
return ""
|
|
|
|
|
|
async def fetch_images(urls: List[str]) -> Tuple[str]:
|
|
tasks = [fetch_image(url) for url in urls]
|
|
return await asyncio.gather(*tasks)
|