Provide a way to provide json data directly

This commit is contained in:
Dan Hess 2021-03-31 23:34:34 -08:00
parent 06b2752732
commit 80772d9374
2 changed files with 5 additions and 2 deletions

View File

@ -72,7 +72,7 @@ query ($name: String) {
url = "https://graphql.anilist.co"
payload = {"query": query, "variables": {"name": username}}
response = await request(url, method="POST", payload=payload)
response = await request(url, method="POST", json_data=payload)
# Anilist API is broken and doesn't filter correctly, guess we have to do that ourselves
data = []

View File

@ -29,6 +29,7 @@ async def request(
*,
headers=None,
payload=None,
json_data=None,
method="GET",
attr="json",
force_content_type_json=False,
@ -45,7 +46,9 @@ async def request(
# Create the session with our headeres
async with aiohttp.ClientSession(headers=headers) as session:
# Make the request, based on the method, url, and paramaters given
async with session.request(method, url, params=payload) as response:
async with session.request(
method, url, params=payload, json=json_data
) as response:
# If the request wasn't successful, re-attempt
if response.status != 200:
continue