@@ -4,6 +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, timedelta
8+import re
79
810categories = ['news']
911search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
@@ -11,6 +13,7 @@ results_xpath = '//div[@class="res"]'
1113url_xpath = './/h3/a/@href'
1214title_xpath = './/h3/a'
1315content_xpath = './/div[@class="abstr"]'
16+publishedDate_xpath = './/span[@class="timestamp"]'
1417suggestion_xpath = '//div[@id="satat"]//a'
1518
1619paging = True
@@ -37,7 +40,22 @@ def response(resp):
3740 url = parse_url(extract_url(result.xpath(url_xpath), search_url))
3841 title = extract_text(result.xpath(title_xpath)[0])
3942 content = extract_text(result.xpath(content_xpath)[0])
40− results.append({'url': url, 'title': title, 'content': content})
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+
58+ results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
4159
4260 if not suggestion_xpath:
4361 return results