aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py20
1 files changed, 9 insertions, 11 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 2ce266b..05ebaaa 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -3447,13 +3447,12 @@ class Mastodon:
3447 every time instead of randomly doing different things on some systems 3447 every time instead of randomly doing different things on some systems
3448 and also it represents that time as the equivalent UTC time. 3448 and also it represents that time as the equivalent UTC time.
3449 """ 3449 """
3450 isotime = datetime_val.astimezone( 3450 isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
3451 pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
3452 if isotime[-2] != ":": 3451 if isotime[-2] != ":":
3453 isotime = isotime[:-2] + ":" + isotime[-2:] 3452 isotime = isotime[:-2] + ":" + isotime[-2:]
3454 return isotime 3453 return isotime
3455 3454
3456 def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, base_url_override=None, do_ratelimiting=True, use_json=False, parse=True): 3455 def __api_request(self, method, endpoint, params={}, files={}, headers={}, access_token_override=None, base_url_override=None, do_ratelimiting=True, use_json=False, parse=True, return_response_object=False):
3457 """ 3456 """
3458 Internal API request helper. 3457 Internal API request helper.
3459 """ 3458 """
@@ -3471,8 +3470,7 @@ class Mastodon:
3471 time.sleep(to_next) 3470 time.sleep(to_next)
3472 else: 3471 else:
3473 time_waited = time.time() - self.ratelimit_lastcall 3472 time_waited = time.time() - self.ratelimit_lastcall
3474 time_wait = float(self.ratelimit_reset - 3473 time_wait = float(self.ratelimit_reset - time.time()) / float(self.ratelimit_remaining)
3475 time.time()) / float(self.ratelimit_remaining)
3476 remaining_wait = time_wait - time_waited 3474 remaining_wait = time_wait - time_waited
3477 3475
3478 if remaining_wait > 0: 3476 if remaining_wait > 0:
@@ -3510,8 +3508,7 @@ class Mastodon:
3510 3508
3511 response_object = None 3509 response_object = None
3512 try: 3510 try:
3513 kwargs = dict(headers=headers, files=files, 3511 kwargs = dict(headers=headers, files=files, timeout=self.request_timeout)
3514 timeout=self.request_timeout)
3515 if use_json == False: 3512 if use_json == False:
3516 if method == 'GET': 3513 if method == 'GET':
3517 kwargs['params'] = params 3514 kwargs['params'] = params
@@ -3565,10 +3562,8 @@ class Mastodon:
3565 3562
3566 # Adjust server time to local clock 3563 # Adjust server time to local clock
3567 if 'Date' in response_object.headers: 3564 if 'Date' in response_object.headers:
3568 server_time_datetime = dateutil.parser.parse( 3565 server_time_datetime = dateutil.parser.parse(response_object.headers['Date'])
3569 response_object.headers['Date']) 3566 server_time = self.__datetime_to_epoch(server_time_datetime)
3570 server_time = self.__datetime_to_epoch(
3571 server_time_datetime)
3572 server_time_diff = time.time() - server_time 3567 server_time_diff = time.time() - server_time
3573 self.ratelimit_reset += server_time_diff 3568 self.ratelimit_reset += server_time_diff
3574 self.ratelimit_lastcall = time.time() 3569 self.ratelimit_lastcall = time.time()
@@ -3637,6 +3632,9 @@ class Mastodon:
3637 response_object.status_code, 3632 response_object.status_code,
3638 response_object.reason, 3633 response_object.reason,
3639 error_msg) 3634 error_msg)
3635
3636 if return_response_object:
3637 return response_object
3640 3638
3641 if parse == True: 3639 if parse == True:
3642 try: 3640 try:
Powered by cgit v1.2.3 (git 2.41.0)