1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-11-01 13:02:38 +00:00

Add POST requests to fetch method for Kheina API

This commit is contained in:
Myned 2020-03-18 02:17:58 -04:00
parent 4ba0ce153d
commit a6431ca4c3
No known key found for this signature in database
GPG key ID: 2EF9C0C44229D034

View file

@ -84,17 +84,34 @@ last_commands = {}
asession = aiohttp.ClientSession()
async def fetch(url, *, json=False, response=False, text=False):
async def fetch(url, *, post={}, response=False, text=False, json=False):
if '.json' in url and ('e621' in url or 'e926' in url):
url += f'&login=BotMyned&api_key={config["e621_api"]}'
async with asession.get(url, headers={
if post:
async with asession.post(url, data=post, headers={
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
if response:
if r.status != 200:
return r.status
elif response:
return r
elif json:
return await r.json()
elif text:
return await r.text()
elif json:
return await r.json()
else:
return await r.read()
else:
async with asession.get(url, headers={
'User-Agent': 'Myned/Modufur (https://github.com/Myned/Modufur)'}, ssl=False) as r:
if r.status != 200:
return r.status
elif response:
return r
elif text:
return await r.text()
elif json:
return await r.json()
else:
return await r.read()