aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py2
-rw-r--r--mastodon/internals.py16
2 files changed, 6 insertions, 12 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index c454aa1..ad8e963 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -7,6 +7,7 @@ import os.path
7import time 7import time
8import datetime 8import datetime
9import collections 9import collections
10from contextlib import closing
10import requests 11import requests
11from requests.models import urlencode 12from requests.models import urlencode
12import dateutil 13import dateutil
@@ -3744,4 +3745,3 @@ class Mastodon(Internals):
3744 if api_okay in [b'OK', b'success']: 3745 if api_okay in [b'OK', b'success']:
3745 return True 3746 return True
3746 return False 3747 return False
3747
diff --git a/mastodon/internals.py b/mastodon/internals.py
index a19ed77..415e22d 100644
--- a/mastodon/internals.py
+++ b/mastodon/internals.py
@@ -4,7 +4,6 @@ import mimetypes
4import threading 4import threading
5import six 5import six
6import uuid 6import uuid
7import pytz
8import dateutil.parser 7import dateutil.parser
9import time 8import time
10import copy 9import copy
@@ -24,7 +23,7 @@ from .defaults import _DEFAULT_STREAM_TIMEOUT, _DEFAULT_STREAM_RECONNECT_WAIT_SE
24### 23###
25# Internal helpers, dragons probably 24# Internal helpers, dragons probably
26### 25###
27class Mastodon(): 26class Mastodon():
28 def __datetime_to_epoch(self, date_time): 27 def __datetime_to_epoch(self, date_time):
29 """ 28 """
30 Converts a python datetime to unix epoch, accounting for 29 Converts a python datetime to unix epoch, accounting for
@@ -32,15 +31,10 @@ class Mastodon():
32 31
33 Assumes UTC if timezone is not given. 32 Assumes UTC if timezone is not given.
34 """ 33 """
35 date_time_utc = None
36 if date_time.tzinfo is None: 34 if date_time.tzinfo is None:
37 date_time_utc = date_time.replace(tzinfo=pytz.utc) 35 date_time = date_time.replace(tzinfo=datetime.timezone.utc)
38 else: 36 return date_time.timestamp()
39 date_time_utc = date_time.astimezone(pytz.utc)
40
41 epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
42 37
43 return (date_time_utc - epoch_utc).total_seconds()
44 38
45 def __get_logged_in_id(self): 39 def __get_logged_in_id(self):
46 """ 40 """
@@ -73,7 +67,7 @@ class Mastodon():
73 if v is not None: 67 if v is not None:
74 try: 68 try:
75 if isinstance(v, int): 69 if isinstance(v, int):
76 json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) 70 json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc)
77 else: 71 else:
78 json_object[k] = dateutil.parser.parse(v) 72 json_object[k] = dateutil.parser.parse(v)
79 except: 73 except:
@@ -129,7 +123,7 @@ class Mastodon():
129 every time instead of randomly doing different things on some systems 123 every time instead of randomly doing different things on some systems
130 and also it represents that time as the equivalent UTC time. 124 and also it represents that time as the equivalent UTC time.
131 """ 125 """
132 isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") 126 isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
133 if isotime[-2] != ":": 127 if isotime[-2] != ":":
134 isotime = isotime[:-2] + ":" + isotime[-2:] 128 isotime = isotime[:-2] + ":" + isotime[-2:]
135 return isotime 129 return isotime
Powered by cgit v1.2.3 (git 2.41.0)