|
|
|
|
|
|
|
|
import aiohttp |
|
|
import aiohttp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def api_request(url, *, headers=None): |
|
|
|
|
|
|
|
|
async def request(url, *, headers=None, **kwargs): |
|
|
|
|
|
""" |
|
|
|
|
|
Base GET request. |
|
|
|
|
|
:param url: |
|
|
|
|
|
:param headers: |
|
|
|
|
|
:param kwargs: |
|
|
|
|
|
:return: |
|
|
|
|
|
""" |
|
|
|
|
|
async with aiohttp.ClientSession() as session: |
|
|
|
|
|
return await session.get(url, headers=headers, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def api_request(url, *, headers=None, **kwargs): |
|
|
""" |
|
|
""" |
|
|
Returns a JSON dict object for most api calls in RoxBot. |
|
|
Returns a JSON dict object for most api calls in RoxBot. |
|
|
:param url: URL Should be a api endpoint that will return |
|
|
:param url: URL Should be a api endpoint that will return |
|
|
|
|
|
|
|
|
headers = {'User-agent': 'RoxBot Discord Bot'} |
|
|
headers = {'User-agent': 'RoxBot Discord Bot'} |
|
|
else: |
|
|
else: |
|
|
headers = {'User-agent': 'RoxBot Discord Bot', **headers} |
|
|
headers = {'User-agent': 'RoxBot Discord Bot', **headers} |
|
|
async with aiohttp.ClientSession() as session: |
|
|
|
|
|
async with session.get(url, headers=headers) as resp: |
|
|
|
|
|
try: |
|
|
|
|
|
return json.loads(await resp.read()) |
|
|
|
|
|
except json.JSONDecodeError: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
resp = await request(url, headers=headers, **kwargs) |
|
|
|
|
|
try: |
|
|
|
|
|
return json.loads(await resp.read()) |
|
|
|
|
|
except json.JSONDecodeError: |
|
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def download_file(url, filename=None): |
|
|
async def download_file(url, filename=None): |