15 lines
570 B
Python
15 lines
570 B
Python
from aiohttp import ClientSession, ClientTimeout
|
|
from app.config import CUSTOM_USER_AGENT
|
|
|
|
async def fetch_url(url: str) -> tuple[str, int]:
|
|
"""
|
|
Fetch a URL using aiohttp and return the content and status code
|
|
"""
|
|
timeout = ClientTimeout(total=30) # 30 second timeout
|
|
async with ClientSession(timeout=timeout) as session:
|
|
headers = {
|
|
'User-Agent': CUSTOM_USER_AGENT
|
|
}
|
|
async with session.get(url, headers=headers) as response:
|
|
content = await response.text()
|
|
return content, response.status |