diff options
author | Adam Tauber <asciimoo@gmail.com> | 2017-04-08 19:42:50 +0200 |
---|---|---|
committer | Adam Tauber <asciimoo@gmail.com> | 2017-04-08 19:45:04 +0200 |
commit | 46a2c63f8e1c3819cceff2d61fe9106051e8ecee (patch) | |
tree | c95a01281e26149638c423ba96b9d936703c772d | |
parent | 12d91c1d67aa4c05ecead7ff16041fb2b9ca366d (diff) | |
download | searxng-46a2c63f8e1c3819cceff2d61fe9106051e8ecee.tar.gz searxng-46a2c63f8e1c3819cceff2d61fe9106051e8ecee.zip |
[fix] yahoo news date parsing
-rw-r--r-- | searx/engines/yahoo_news.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/searx/engines/yahoo_news.py b/searx/engines/yahoo_news.py index 3e4cf02eb..1a0fd28f5 100644 --- a/searx/engines/yahoo_news.py +++ b/searx/engines/yahoo_news.py @@ -80,16 +80,19 @@ def response(resp): # still useful ? if re.match("^[0-9]+ minute(s|) ago$", publishedDate): - publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group())) # noqa + publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group())) + elif re.match("^[0-9]+ days? ago$", publishedDate): + publishedDate = datetime.now() - timedelta(days=int(re.match(r'\d+', publishedDate).group())) + elif re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", publishedDate): + timeNumbers = re.findall(r'\d+', publishedDate) + publishedDate = datetime.now()\ + - timedelta(hours=int(timeNumbers[0]))\ + - timedelta(minutes=int(timeNumbers[1])) else: - if re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", - publishedDate): - timeNumbers = re.findall(r'\d+', publishedDate) - publishedDate = datetime.now()\ - - timedelta(hours=int(timeNumbers[0]))\ - - timedelta(minutes=int(timeNumbers[1])) - else: + try: publishedDate = parser.parse(publishedDate) + except: + publishedDate = datetime.now() if publishedDate.year == 1900: publishedDate = publishedDate.replace(year=datetime.now().year) |