Merge branch 'master' of github.com:gled-rs/Mastodon.py
This commit is contained in:
commit
3efd0504c0
S'han modificat 1 arxius amb 16 adicions i 3 eliminacions
|
@ -381,7 +381,7 @@ class Mastodon:
|
||||||
|
|
||||||
Returns a list of user dicts.
|
Returns a list of user dicts.
|
||||||
"""
|
"""
|
||||||
return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/following')
|
return self.__api_request('GET', '/api/v1/accounts/' + str(id) + '/following',do_fetch_all=True)
|
||||||
|
|
||||||
def account_followers(self, id):
|
def account_followers(self, id):
|
||||||
"""
|
"""
|
||||||
|
@ -718,12 +718,13 @@ class Mastodon:
|
||||||
|
|
||||||
return (date_time_utc - epoch_utc).total_seconds()
|
return (date_time_utc - epoch_utc).total_seconds()
|
||||||
|
|
||||||
def __api_request(self, method, endpoint, params = {}, files = {}, do_ratelimiting = True):
|
def __api_request(self, method, endpoint, params = {}, files = {}, do_ratelimiting = True, do_fetch_all = False):
|
||||||
"""
|
"""
|
||||||
Internal API request helper.
|
Internal API request helper.
|
||||||
"""
|
"""
|
||||||
response = None
|
response = None
|
||||||
headers = None
|
headers = None
|
||||||
|
next_url = None
|
||||||
|
|
||||||
# "pace" mode ratelimiting: Assume constant rate of requests, sleep a little less long than it
|
# "pace" mode ratelimiting: Assume constant rate of requests, sleep a little less long than it
|
||||||
# would take to not hit the rate limit at that request rate.
|
# would take to not hit the rate limit at that request rate.
|
||||||
|
@ -781,7 +782,7 @@ class Mastodon:
|
||||||
if self.debug_requests == True:
|
if self.debug_requests == True:
|
||||||
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')
|
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')
|
||||||
print('response headers: ' + str(response_object.headers))
|
print('response headers: ' + str(response_object.headers))
|
||||||
print('Response text content: ' + str(response_object.text))
|
#print('Response text content: ' + str(response_object.text))
|
||||||
|
|
||||||
if response_object.status_code == 404:
|
if response_object.status_code == 404:
|
||||||
raise MastodonAPIError('Endpoint not found.')
|
raise MastodonAPIError('Endpoint not found.')
|
||||||
|
@ -796,6 +797,18 @@ class Mastodon:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise MastodonAPIError("Could not parse response as JSON, response code was %s, bad json content was '%s'" % (response_object.status_code, response_object.content))
|
raise MastodonAPIError("Could not parse response as JSON, response code was %s, bad json content was '%s'" % (response_object.status_code, response_object.content))
|
||||||
|
|
||||||
|
if 'Link' in response_object.headers and do_fetch_all:
|
||||||
|
tmp_url = requests.utils.parse_header_links(response_object.headers['Link'].rstrip('>').replace('>,<', ',<'))
|
||||||
|
if tmp_url:
|
||||||
|
for url in tmp_url:
|
||||||
|
if url['rel'] == 'next':
|
||||||
|
next_url = url['url'].replace(self.api_base_url,'')
|
||||||
|
break
|
||||||
|
if next_url is not None:
|
||||||
|
tmp_response = self.__api_request(method, next_url, params = params, files = files, do_ratelimiting = do_ratelimiting, do_fetch_all = True)
|
||||||
|
if type(tmp_response) == type(response):
|
||||||
|
response += tmp_response
|
||||||
|
|
||||||
# Handle rate limiting
|
# Handle rate limiting
|
||||||
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
if 'X-RateLimit-Remaining' in response_object.headers and do_ratelimiting:
|
||||||
self.ratelimit_remaining = int(response_object.headers['X-RateLimit-Remaining'])
|
self.ratelimit_remaining = int(response_object.headers['X-RateLimit-Remaining'])
|
||||||
|
|
Loading…
Referencia en una nova incidència