summaryrefslogtreecommitdiff
path: root/ATRI/utils/request.py
blob: 04d70936464c8d8db46aac2feefa5163a8e030be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import httpx

from ATRI.config import BotSelfConfig
from ATRI.log import logger as log


if not BotSelfConfig.proxy:
    proxy = dict()
else:
    proxy = {"all://": BotSelfConfig.proxy}


async def get(url: str, **kwargs):
    log.debug(f"GET {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}")
    async with httpx.AsyncClient(proxies=proxy) as client:  # type: ignore
        return await client.get(url, **kwargs)


async def post(url: str, **kwargs):
    log.debug(f"POST {url} by {proxy if proxy else 'No proxy'} | MORE: \n {kwargs}")
    async with httpx.AsyncClient(proxies=proxy) as client:  # type: ignore
        return await client.post(url, **kwargs)