aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhalcy <halcy@ARARAGI-KUN>2022-11-30 22:43:03 +0200
committerhalcy <halcy@ARARAGI-KUN>2022-11-30 22:43:03 +0200
commit2d7f495b0f702ca156697e7c7f0dd2e40a68e4a6 (patch)
tree06b61042d1a76694422a517bada8aebf6103927c
parent262d150c05b328324ae5becc5da0d5b55dd74b89 (diff)
parentbf428f58efbf7989d7771e9edb54fade1009a4e7 (diff)
downloadmastodon.py-2d7f495b0f702ca156697e7c7f0dd2e40a68e4a6.tar.gz
Merge branch 'modern-datetime' of https://github.com/eumiro/Mastodon.py into eumiro-modern-datetime
-rw-r--r--mastodon/Mastodon.py2
-rw-r--r--mastodon/internals.py16
-rw-r--r--setup.py1
-rw-r--r--tests/test_status.py4
4 files changed, 8 insertions, 15 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
diff --git a/setup.py b/setup.py
index 1f03b30..29feedb 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,6 @@ setup(name='Mastodon.py',
33 'requests>=2.4.2', 33 'requests>=2.4.2',
34 'python-dateutil', 34 'python-dateutil',
35 'six', 35 'six',
36 'pytz',
37 'python-magic', 36 'python-magic',
38 'decorator>=4.0.0', 37 'decorator>=4.0.0',
39 ] + blurhash_deps, 38 ] + blurhash_deps,
diff --git a/tests/test_status.py b/tests/test_status.py
index e747571..1fa7fd5 100644
--- a/tests/test_status.py
+++ b/tests/test_status.py
@@ -1,7 +1,7 @@
1import pytest 1import pytest
2from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError 2from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError
3import datetime 3import datetime
4import pytz 4import zoneinfo
5import vcr 5import vcr
6import time 6import time
7import pickle 7import pickle
@@ -154,7 +154,7 @@ def test_status_pin_unpin(status, api):
154 154
155@pytest.mark.vcr(match_on=['path']) 155@pytest.mark.vcr(match_on=['path'])
156def test_scheduled_status(api): 156def test_scheduled_status(api):
157 base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, pytz.timezone("Etc/GMT+2")) 157 base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, zoneinfo.ZoneInfo("Etc/GMT+2"))
158 the_future = base_time + datetime.timedelta(minutes=20) 158 the_future = base_time + datetime.timedelta(minutes=20)
159 scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future) 159 scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future)
160 assert scheduled_toot 160 assert scheduled_toot
Powered by cgit v1.2.3 (git 2.41.0)