Commit a5bae83e authored by Joshua Roesslein's avatar Joshua Roesslein
Browse files

Refactor parse_datetime util.

- Avoid changing locale to parse timestamps.
- Use emails RFC 2822 parser.
- Added a test.
parent 3f24fec6
#! /usr/bin/env bash
if [[ $TRAVIS_SECURE_ENV_VARS == "false" ]]; then
USE_REPLAY=1 nosetests -v tests.test_api
USE_REPLAY=1 nosetests -v tests.test_api tests.test_utils
nosetests -v tests.test_api tests.test_streaming tests.test_cursors
nosetests -v tests.test_api tests.test_streaming tests.test_cursors tests.test_utils
from unittest import TestCase
from tweepy.utils import *
class TweepyUtilsTests(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)
......@@ -8,19 +8,11 @@ import htmlentitydefs
import re
import locale
from urllib import quote
from email.utils import parsedate
def parse_datetime(string):
# Set locale for date parsing
locale.setlocale(locale.LC_TIME, 'C')
# We must parse datetime this way to work in python 2.4
date = datetime(*(time.strptime(string, '%a %b %d %H:%M:%S +0000 %Y')[0:6]))
# Reset locale back to the default setting
locale.setlocale(locale.LC_TIME, '')
return date
return datetime(*(parsedate(string)[:6]))
def parse_html_value(html):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment