Allow the use of forcing content_type for json
This commit is contained in:
parent
28e912728b
commit
46a1280256
|
@ -30,7 +30,7 @@ class Stats:
|
||||||
# We need to page through, so lets create a loop and break when we find out we're done
|
# We need to page through, so lets create a loop and break when we find out we're done
|
||||||
while True:
|
while True:
|
||||||
# Simply get data based on the URL
|
# Simply get data based on the URL
|
||||||
data = await utils.request(url, headers=headers)
|
data = await utils.request(url, headers=headers, force_content_type_json=True)
|
||||||
# First check if the data failed to retrieve, if so just return
|
# First check if the data failed to retrieve, if so just return
|
||||||
if data is None:
|
if data is None:
|
||||||
return
|
return
|
||||||
|
@ -40,11 +40,12 @@ class Stats:
|
||||||
# We only carry about the user's
|
# We only carry about the user's
|
||||||
if include['type'] != 'user':
|
if include['type'] != 'user':
|
||||||
continue
|
continue
|
||||||
# This check checks the user's connected campaign (should only exist for *our* user) and checks if it matches
|
# This check checks the user's connected campaign (should only exist for *our* user) and checks if it
|
||||||
|
# matches
|
||||||
if include.get('relationshipos', {}).get('campaign', {}).get('data', {}).get('id', {}) == str(utils.patreon_id):
|
if include.get('relationshipos', {}).get('campaign', {}).get('data', {}).get('id', {}) == str(utils.patreon_id):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Otherwuse the only way this user was included, was if they are a patron, so include them
|
# Otherwise the only way this user was included, was if they are a patron, so include them
|
||||||
name = include['attributes']['full_name']
|
name = include['attributes']['full_name']
|
||||||
if name:
|
if name:
|
||||||
names.append(name)
|
names.append(name)
|
||||||
|
|
|
@ -60,7 +60,7 @@ async def download_image(url):
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
async def request(url, *, headers=None, payload=None, method='GET', attr='json'):
|
async def request(url, *, headers=None, payload=None, method='GET', attr='json', force_content_type_json=False):
|
||||||
# Make sure our User Agent is what's set, and ensure it's sent even if no headers are passed
|
# Make sure our User Agent is what's set, and ensure it's sent even if no headers are passed
|
||||||
if headers is None:
|
if headers is None:
|
||||||
headers = {}
|
headers = {}
|
||||||
|
@ -83,7 +83,13 @@ async def request(url, *, headers=None, payload=None, method='GET', attr='json')
|
||||||
return_value = getattr(response, attr)
|
return_value = getattr(response, attr)
|
||||||
# Next check if this can be called
|
# Next check if this can be called
|
||||||
if callable(return_value):
|
if callable(return_value):
|
||||||
return_value = return_value()
|
# This is use for json; it checks the mimetype instead of checking if the actual data
|
||||||
|
# This causes some places with different mimetypes to fail, even if it's valid json
|
||||||
|
# This check allows us to force the content_type to use whatever content type is given
|
||||||
|
if force_content_type_json:
|
||||||
|
return_value = return_value(content_type=response.headers['content-type'])
|
||||||
|
else:
|
||||||
|
return_value = return_value()
|
||||||
# If this is awaitable, await it
|
# If this is awaitable, await it
|
||||||
if inspect.isawaitable(return_value):
|
if inspect.isawaitable(return_value):
|
||||||
return_value = await return_value
|
return_value = await return_value
|
||||||
|
|
Loading…
Reference in a new issue