@@ -4,7 +4,8 @@ from urllib import urlencode
44from lxml import html
55from searx.engines.xpath import extract_text, extract_url
66from searx.engines.yahoo import parse_url
7−from datetime import datetime
7+from datetime import datetime, timedelta
8+import re
89
910categories = ['news']
1011search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
@@ -39,9 +40,21 @@ def response(resp):
3940 url = parse_url(extract_url(result.xpath(url_xpath), search_url))
4041 title = extract_text(result.xpath(title_xpath)[0])
4142 content = extract_text(result.xpath(content_xpath)[0])
42−# Feb 20 04:02am
43− publishedDate = datetime.strptime(extract_text(result.xpath(publishedDate_xpath)[0]),"%b %d %H:%M%p")
44− #publishedDate.replace(year=2014)
43+ publishedDate = extract_text(result.xpath(publishedDate_xpath)[0])
44+
45+ if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
46+ publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group()))
47+ else:
48+ if re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", publishedDate):
49+ timeNumbers = re.findall(r'\d+', publishedDate)
50+ publishedDate = datetime.now() - timedelta(hours=int(timeNumbers[0])) - timedelta(minutes=int(timeNumbers[1]))
51+ else:
52+ # TODO year in string possible?
53+ publishedDate = datetime.strptime(publishedDate,"%b %d %H:%M%p")
54+
55+ if publishedDate.year == 1900:
56+ publishedDate = publishedDate.replace(year=datetime.now().year)
57+
4558 results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
4659
4760 if not suggestion_xpath: