kopia lustrzana https://github.com/halcy/Mastodon.py
Merge branch 'eumiro-modern-datetime'
commit
99432f538e
|
@ -7,6 +7,7 @@ import os.path
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
import collections
|
import collections
|
||||||
|
from contextlib import closing
|
||||||
import requests
|
import requests
|
||||||
from requests.models import urlencode
|
from requests.models import urlencode
|
||||||
import dateutil
|
import dateutil
|
||||||
|
@ -3744,4 +3745,3 @@ class Mastodon(Internals):
|
||||||
if api_okay in [b'OK', b'success']:
|
if api_okay in [b'OK', b'success']:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import mimetypes
|
||||||
import threading
|
import threading
|
||||||
import six
|
import six
|
||||||
import uuid
|
import uuid
|
||||||
import pytz
|
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
import time
|
import time
|
||||||
import copy
|
import copy
|
||||||
|
@ -32,15 +31,10 @@ class Mastodon():
|
||||||
|
|
||||||
Assumes UTC if timezone is not given.
|
Assumes UTC if timezone is not given.
|
||||||
"""
|
"""
|
||||||
date_time_utc = None
|
|
||||||
if date_time.tzinfo is None:
|
if date_time.tzinfo is None:
|
||||||
date_time_utc = date_time.replace(tzinfo=pytz.utc)
|
date_time = date_time.replace(tzinfo=datetime.timezone.utc)
|
||||||
else:
|
return date_time.timestamp()
|
||||||
date_time_utc = date_time.astimezone(pytz.utc)
|
|
||||||
|
|
||||||
epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
|
|
||||||
|
|
||||||
return (date_time_utc - epoch_utc).total_seconds()
|
|
||||||
|
|
||||||
def __get_logged_in_id(self):
|
def __get_logged_in_id(self):
|
||||||
"""
|
"""
|
||||||
|
@ -73,7 +67,7 @@ class Mastodon():
|
||||||
if v is not None:
|
if v is not None:
|
||||||
try:
|
try:
|
||||||
if isinstance(v, int):
|
if isinstance(v, int):
|
||||||
json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc)
|
json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc)
|
||||||
else:
|
else:
|
||||||
json_object[k] = dateutil.parser.parse(v)
|
json_object[k] = dateutil.parser.parse(v)
|
||||||
except:
|
except:
|
||||||
|
@ -129,7 +123,7 @@ class Mastodon():
|
||||||
every time instead of randomly doing different things on some systems
|
every time instead of randomly doing different things on some systems
|
||||||
and also it represents that time as the equivalent UTC time.
|
and also it represents that time as the equivalent UTC time.
|
||||||
"""
|
"""
|
||||||
isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
|
isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z")
|
||||||
if isotime[-2] != ":":
|
if isotime[-2] != ":":
|
||||||
isotime = isotime[:-2] + ":" + isotime[-2:]
|
isotime = isotime[:-2] + ":" + isotime[-2:]
|
||||||
return isotime
|
return isotime
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -33,7 +33,6 @@ setup(name='Mastodon.py',
|
||||||
'requests>=2.4.2',
|
'requests>=2.4.2',
|
||||||
'python-dateutil',
|
'python-dateutil',
|
||||||
'six',
|
'six',
|
||||||
'pytz',
|
|
||||||
'python-magic',
|
'python-magic',
|
||||||
'decorator>=4.0.0',
|
'decorator>=4.0.0',
|
||||||
] + blurhash_deps,
|
] + blurhash_deps,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError
|
from mastodon.Mastodon import MastodonAPIError, MastodonNotFoundError
|
||||||
import datetime
|
import datetime
|
||||||
import pytz
|
import zoneinfo
|
||||||
import vcr
|
import vcr
|
||||||
import time
|
import time
|
||||||
import pickle
|
import pickle
|
||||||
|
@ -154,7 +154,7 @@ def test_status_pin_unpin(status, api):
|
||||||
|
|
||||||
@pytest.mark.vcr(match_on=['path'])
|
@pytest.mark.vcr(match_on=['path'])
|
||||||
def test_scheduled_status(api):
|
def test_scheduled_status(api):
|
||||||
base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, pytz.timezone("Etc/GMT+2"))
|
base_time = datetime.datetime(4000, 1, 1, 12, 13, 14, 0, zoneinfo.ZoneInfo("Etc/GMT+2"))
|
||||||
the_future = base_time + datetime.timedelta(minutes=20)
|
the_future = base_time + datetime.timedelta(minutes=20)
|
||||||
scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future)
|
scheduled_toot = api.status_post("please ensure adequate headroom", scheduled_at=the_future)
|
||||||
assert scheduled_toot
|
assert scheduled_toot
|
||||||
|
|
Ładowanie…
Reference in New Issue