summaryrefslogtreecommitdiff
path: root/searx/engines/yahoo_news.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-03-15 19:20:29 +0100
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-03-15 19:20:29 +0100
commit5538c6771abacb9dab504fa7da0052c443b14f13 (patch)
treeecc0b0113e6e2797ca2f88f04ad73202f8a8e6bf /searx/engines/yahoo_news.py
parent794165d19cbf91b62d45e93c9a2f387346b89c7b (diff)
downloadsearxng-5538c6771abacb9dab504fa7da0052c443b14f13.tar.gz
searxng-5538c6771abacb9dab504fa7da0052c443b14f13.zip
improve publishDate extraction from yahoo
Diffstat (limited to 'searx/engines/yahoo_news.py')
-rw-r--r--searx/engines/yahoo_news.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/searx/engines/yahoo_news.py b/searx/engines/yahoo_news.py
index c9789240d..13a8a6024 100644
--- a/searx/engines/yahoo_news.py
+++ b/searx/engines/yahoo_news.py
@@ -4,7 +4,8 @@ from urllib import urlencode
from lxml import html
from searx.engines.xpath import extract_text, extract_url
from searx.engines.yahoo import parse_url
-from datetime import datetime
+from datetime import datetime, timedelta
+import re
categories = ['news']
search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
@@ -39,9 +40,21 @@ def response(resp):
url = parse_url(extract_url(result.xpath(url_xpath), search_url))
title = extract_text(result.xpath(title_xpath)[0])
content = extract_text(result.xpath(content_xpath)[0])
-# Feb 20 04:02am
- publishedDate = datetime.strptime(extract_text(result.xpath(publishedDate_xpath)[0]),"%b %d %H:%M%p")
- #publishedDate.replace(year=2014)
+ publishedDate = extract_text(result.xpath(publishedDate_xpath)[0])
+
+ if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
+ publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group()))
+ 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:
+ # TODO year in string possible?
+ publishedDate = datetime.strptime(publishedDate,"%b %d %H:%M%p")
+
+ if publishedDate.year == 1900:
+ publishedDate = publishedDate.replace(year=datetime.now().year)
+
results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
if not suggestion_xpath: