-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix HDSpace pubdate parsing #5111
Changes from 8 commits
748495d
20b0100
6156571
e1a1e3f
57ad8d7
c8dfb86
d54dd37
97f4d66
d3caa62
39028bf
5e544be
377fe65
f3047ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -574,12 +574,25 @@ def parse_pubdate(pubdate, human_time=False, timezone=None, **kwargs): | |
matched_time = int(round(float(matched_time.strip()))) | ||
|
||
seconds = parse('{0} {1}'.format(matched_time, matched_granularity)) | ||
if seconds is None: | ||
log.warning('Failed parsing human time: {0} {1}', matched_time, matched_granularity) | ||
raise ValueError('Failed parsing human time: {0} {1}'.format(matched_time, matched_granularity)) | ||
return datetime.now(tz.tzlocal()) - timedelta(seconds=seconds) | ||
|
||
if fromtimestamp: | ||
dt = datetime.fromtimestamp(int(pubdate), tz=tz.gettz('UTC')) | ||
else: | ||
dt = parser.parse(pubdate, dayfirst=df, yearfirst=yf, fuzzy=True) | ||
from tzlocal import get_localzone | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Forgot to remove the import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @p0psicles You marked as resolved but the import is still there |
||
day_offset = 0 | ||
if 'yesterday at' in pubdate.lower() or 'today at' in pubdate.lower(): | ||
# Extract a time | ||
time = re.search(r'(?P<time>[0-9:]+)', pubdate) | ||
if time: | ||
if 'yesterday' in pubdate: | ||
day_offset = 1 | ||
pubdate = time.group('time') | ||
|
||
dt = parser.parse(pubdate.strip(), dayfirst=df, yearfirst=yf, fuzzy=True) - timedelta(days=day_offset) | ||
|
||
# Always make UTC aware if naive | ||
if dt.tzinfo is None or dt.tzinfo.utcoffset(dt) is None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"""Provider test code for Generic Provider.""" | ||
from __future__ import unicode_literals | ||
|
||
from datetime import date, datetime | ||
from datetime import date, datetime, timedelta | ||
|
||
from dateutil import tz | ||
|
||
|
@@ -127,6 +127,16 @@ | |
'timezone': 'US/Eastern', | ||
'fromtimestamp': True | ||
}, | ||
{ # p22: hd-space test human date like yesterdat at 12:00:00 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: |
||
'pubdate': 'yesterday at {0}'.format((datetime.now() - timedelta(minutes=10, seconds=25)).strftime('%H:%M:%S')), | ||
'expected': datetime.now().replace(microsecond=0, tzinfo=tz.gettz('UTC')) - timedelta(days=1, minutes=10, seconds=25), | ||
'human_time': False | ||
}, | ||
{ # p22: hd-space test human date like today at 12:00:00 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
'pubdate': 'today at {0}'.format((datetime.now() - timedelta(minutes=10, seconds=25)).strftime('%H:%M:%S')), | ||
'expected': datetime.now().replace(microsecond=0, tzinfo=tz.gettz('UTC')) - timedelta(days=0, minutes=10, seconds=25), | ||
'human_time': False | ||
}, | ||
]) | ||
def test_parse_pubdate(p): | ||
# Given | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the warning is needed since it's already going to cause an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but up until now we often had to guess why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but now the exception includes the details you added to the warning log, so you don't really need the log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exeception details are not logged down the stack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see now. Sorry I missed that.