diff options
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 2 | ||||
-rw-r--r-- | mastodon/internals.py | 16 |
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 | |||
7 | import time | 7 | import time |
8 | import datetime | 8 | import datetime |
9 | import collections | 9 | import collections |
10 | from contextlib import closing | ||
10 | import requests | 11 | import requests |
11 | from requests.models import urlencode | 12 | from requests.models import urlencode |
12 | import dateutil | 13 | import 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 | |||
4 | import threading | 4 | import threading |
5 | import six | 5 | import six |
6 | import uuid | 6 | import uuid |
7 | import pytz | ||
8 | import dateutil.parser | 7 | import dateutil.parser |
9 | import time | 8 | import time |
10 | import copy | 9 | import 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 | ### |
27 | class Mastodon(): | 26 | class 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 |