|
@@ -4,6 +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, timedelta
|
|
|
+import re
|
|
|
|
|
|
categories = ['news']
|
|
|
search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
|
|
@@ -11,6 +13,7 @@ results_xpath = '//div[@class="res"]'
|
|
|
url_xpath = './/h3/a/@href'
|
|
|
title_xpath = './/h3/a'
|
|
|
content_xpath = './/div[@class="abstr"]'
|
|
|
+publishedDate_xpath = './/span[@class="timestamp"]'
|
|
|
suggestion_xpath = '//div[@id="satat"]//a'
|
|
|
|
|
|
paging = True
|
|
@@ -37,7 +40,22 @@ 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])
|
|
|
- results.append({'url': url, 'title': title, 'content': content})
|
|
|
+ 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:
|
|
|
return results
|