File size: 520 Bytes
2fcc506
e2b6def
beb9c26
0d18fcb
2fcc506
 
 
0d18fcb
2fcc506
 
0d18fcb
 
2fcc506
 
 
0d18fcb
e2b6def
2fcc506
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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}