@@ -4,7 +4,8 @@ from urllib import urlencode
4from lxml import html
4from lxml import html
5from searx.engines.xpath import extract_text, extract_url
5from searx.engines.xpath import extract_text, extract_url
6from searx.engines.yahoo import parse_url
6from searx.engines.yahoo import parse_url
7−from datetime import datetime
7+from datetime import datetime, timedelta
9categories = ['news']
10categories = ['news']
10search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
11search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
@@ -39,9 +40,21 @@ def response(resp):
39 url = parse_url(extract_url(result.xpath(url_xpath), search_url))
40 url = parse_url(extract_url(result.xpath(url_xpath), search_url))
40 title = extract_text(result.xpath(title_xpath)[0])
41 title = extract_text(result.xpath(title_xpath)[0])
41 content = extract_text(result.xpath(content_xpath)[0])
42 content = extract_text(result.xpath(content_xpath)[0])
43− publishedDate = datetime.strptime(extract_text(result.xpath(publishedDate_xpath)[0]),"%b %d %H:%M%p")
43+ publishedDate = extract_text(result.xpath(publishedDate_xpath)[0])
45+ if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
46+ publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group()))
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]))
52+ # TODO year in string possible?
53+ publishedDate = datetime.strptime(publishedDate,"%b %d %H:%M%p")
55+ if publishedDate.year == 1900:
44− #publishedDate.replace(year=2014)
56+ publishedDate = publishedDate.replace(year=datetime.now().year)
45 results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
58 results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
47 if not suggestion_xpath:
60 if not suggestion_xpath: