From: Harmon Date: Sun, 3 Jan 2021 01:57:43 +0000 (-0600) Subject: Replace parse_datetime function with email.utils.parsedate_to_datetime X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=59d4d920dd4470b52f329d850366721cb52ea0eb;p=tweepy.git Replace parse_datetime function with email.utils.parsedate_to_datetime This causes the datetime objects for created_at attributes to be aware --- diff --git a/tests/test_utils.py b/tests/test_utils.py index 3885167..c7eb012 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,12 +13,7 @@ def mock_tweet(): class TweepyUtilsTests(unittest.TestCase): - def testparse_datetime(self): - result = parse_datetime("Wed Aug 27 13:08:45 +0000 2008") - self.assertEqual(datetime(2008, 8, 27, 13, 8, 45), result) - def testlist_to_csv(self): self.assertEqual("1,2,3", list_to_csv([1,2,3])) self.assertEqual("bird,tweet,nest,egg", list_to_csv(["bird", "tweet", "nest", "egg"])) - diff --git a/tweepy/models.py b/tweepy/models.py index 528ec42..4e88f34 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -2,8 +2,10 @@ # Copyright 2009-2021 Joshua Roesslein # See LICENSE for details. +from email.utils import parsedate_to_datetime + from tweepy.mixins import Hashable -from tweepy.utils import parse_a_href, parse_datetime, parse_html_value +from tweepy.utils import parse_a_href, parse_html_value class ResultSet(list): @@ -96,7 +98,7 @@ class Status(Model, Hashable): setattr(status, 'author', user) setattr(status, 'user', user) # DEPRECIATED elif k == 'created_at': - setattr(status, k, parse_datetime(v)) + setattr(status, k, parsedate_to_datetime(v)) elif k == 'source': if '<' in v: setattr(status, k, parse_html_value(v)) @@ -138,7 +140,7 @@ class User(Model, Hashable): setattr(user, '_json', json) for k, v in json.items(): if k == 'created_at': - setattr(user, k, parse_datetime(v)) + setattr(user, k, parsedate_to_datetime(v)) elif k == 'status': setattr(user, k, Status.parse(api, v)) elif k == 'following': @@ -257,7 +259,7 @@ class SavedSearch(Model): ss = cls(api) for k, v in json.items(): if k == 'created_at': - setattr(ss, k, parse_datetime(v)) + setattr(ss, k, parsedate_to_datetime(v)) else: setattr(ss, k, v) return ss @@ -295,7 +297,7 @@ class List(Model): if k == 'user': setattr(lst, k, User.parse(api, v)) elif k == 'created_at': - setattr(lst, k, parse_datetime(v)) + setattr(lst, k, parsedate_to_datetime(v)) else: setattr(lst, k, v) return lst diff --git a/tweepy/utils.py b/tweepy/utils.py index b173a9c..a2ea4a9 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -2,13 +2,6 @@ # Copyright 2010-2021 Joshua Roesslein # See LICENSE for details. -from datetime import datetime -from email.utils import parsedate - - -def parse_datetime(string): - return datetime(*(parsedate(string)[:6])) - def parse_html_value(html): return html[html.find('>')+1:html.rfind('<')]