forked from Ponysearch/Ponysearch
simplify datetime extraction
This commit is contained in:
parent
fd86bf8189
commit
337bd6d907
5 changed files with 15 additions and 13 deletions
|
@ -3,3 +3,4 @@ flask-babel
|
||||||
grequests
|
grequests
|
||||||
lxml
|
lxml
|
||||||
pyyaml
|
pyyaml
|
||||||
|
python-dateutil
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from dateutil import parser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
categories = ['news']
|
categories = ['news']
|
||||||
|
@ -32,16 +33,9 @@ def response(resp):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
for result in search_res['responseData']['results']:
|
for result in search_res['responseData']['results']:
|
||||||
# S.149 (159), library.pdf
|
|
||||||
# datetime.strptime("Mon, 10 Mar 2014 16:26:15 -0700",
|
# Mon, 10 Mar 2014 16:26:15 -0700
|
||||||
# "%a, %d %b %Y %H:%M:%S %z")
|
publishedDate = parser.parse(result['publishedDate'])
|
||||||
# publishedDate = parse(result['publishedDate'])
|
|
||||||
publishedDate = datetime.strptime(
|
|
||||||
str.join(' ', result['publishedDate'].split(None)[0:5]),
|
|
||||||
"%a, %d %b %Y %H:%M:%S")
|
|
||||||
#utc_offset = timedelta(result['publishedDate'].split(None)[5])
|
|
||||||
# local = utc + offset
|
|
||||||
#publishedDate = publishedDate + utc_offset
|
|
||||||
|
|
||||||
results.append({'url': result['unescapedUrl'],
|
results.append({'url': result['unescapedUrl'],
|
||||||
'title': result['titleNoFormatting'],
|
'title': result['titleNoFormatting'],
|
||||||
|
|
|
@ -6,6 +6,7 @@ from searx.engines.xpath import extract_text, extract_url
|
||||||
from searx.engines.yahoo import parse_url
|
from searx.engines.yahoo import parse_url
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import re
|
import re
|
||||||
|
from dateutil import parser
|
||||||
|
|
||||||
categories = ['news']
|
categories = ['news']
|
||||||
search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
|
search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
|
||||||
|
@ -52,9 +53,7 @@ def response(resp):
|
||||||
- timedelta(hours=int(timeNumbers[0]))\
|
- timedelta(hours=int(timeNumbers[0]))\
|
||||||
- timedelta(minutes=int(timeNumbers[1]))
|
- timedelta(minutes=int(timeNumbers[1]))
|
||||||
else:
|
else:
|
||||||
# TODO year in string possible?
|
publishedDate =parser.parse(publishedDate)
|
||||||
publishedDate = datetime.strptime(publishedDate,
|
|
||||||
"%b %d %H:%M%p")
|
|
||||||
|
|
||||||
if publishedDate.year == 1900:
|
if publishedDate.year == 1900:
|
||||||
publishedDate = publishedDate.replace(year=datetime.now().year)
|
publishedDate = publishedDate.replace(year=datetime.now().year)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from json import loads
|
from json import loads
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
|
from dateutil import parser
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
categories = ['videos']
|
categories = ['videos']
|
||||||
|
|
||||||
|
@ -35,6 +37,10 @@ def response(resp):
|
||||||
content = ''
|
content = ''
|
||||||
thumbnail = ''
|
thumbnail = ''
|
||||||
|
|
||||||
|
#"2013-12-31T15:22:51.000Z"
|
||||||
|
pubdate = result['published']['$t']
|
||||||
|
publishedDate = parser.parse(pubdate)
|
||||||
|
|
||||||
if result['media$group']['media$thumbnail']:
|
if result['media$group']['media$thumbnail']:
|
||||||
thumbnail = result['media$group']['media$thumbnail'][0]['url']
|
thumbnail = result['media$group']['media$thumbnail'][0]['url']
|
||||||
content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, thumbnail) # noqa
|
content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, thumbnail) # noqa
|
||||||
|
@ -48,6 +54,7 @@ def response(resp):
|
||||||
'title': title,
|
'title': title,
|
||||||
'content': content,
|
'content': content,
|
||||||
'template': 'videos.html',
|
'template': 'videos.html',
|
||||||
|
'publishedDate': publishedDate,
|
||||||
'thumbnail': thumbnail})
|
'thumbnail': thumbnail})
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
1
setup.py
1
setup.py
|
@ -35,6 +35,7 @@ setup(
|
||||||
'lxml',
|
'lxml',
|
||||||
'pyyaml',
|
'pyyaml',
|
||||||
'setuptools',
|
'setuptools',
|
||||||
|
'python-dateutil',
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
'test': [
|
'test': [
|
||||||
|
|
Loading…
Reference in a new issue