api / app /fetch.py
Hana Celeste
Update app/fetch.py
2fcc506 verified
raw
history blame contribute delete
520 Bytes
import aiohttp
class Fetcher:
def __init__(self):
self.session = None
async def start(self):
if not self.session:
self.session = aiohttp.ClientSession()
async def stop(self):
if self.session:
await self.session.close()
self.session = None
async def fetch(self, url: str):
async with self.session.get(url, timeout=30) as resp:
text = await resp.text()
return {"ok": True, "status": resp.status, "data": text}