mirror of https://github.com/searxng/searxng.git
[fix] pep8
This commit is contained in:
parent
1467a2e0fc
commit
b735093564
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from json import loads
|
from json import loads
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime
|
||||||
|
|
||||||
categories = ['news']
|
categories = ['news']
|
||||||
|
|
||||||
|
@ -33,10 +33,14 @@ def response(resp):
|
||||||
|
|
||||||
for result in search_res['responseData']['results']:
|
for result in search_res['responseData']['results']:
|
||||||
# S.149 (159), library.pdf
|
# S.149 (159), library.pdf
|
||||||
# datetime.strptime("Mon, 10 Mar 2014 16:26:15 -0700", "%a, %d %b %Y %H:%M:%S %z")
|
# datetime.strptime("Mon, 10 Mar 2014 16:26:15 -0700",
|
||||||
|
# "%a, %d %b %Y %H:%M:%S %z")
|
||||||
# publishedDate = 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")
|
publishedDate = datetime.strptime(
|
||||||
#utc_offset = timedelta(result['publishedDate'].split(None)[5]) # local = utc + offset
|
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
|
#publishedDate = publishedDate + utc_offset
|
||||||
|
|
||||||
results.append({'url': result['unescapedUrl'],
|
results.append({'url': result['unescapedUrl'],
|
||||||
|
|
|
@ -43,19 +43,26 @@ def response(resp):
|
||||||
publishedDate = extract_text(result.xpath(publishedDate_xpath)[0])
|
publishedDate = extract_text(result.xpath(publishedDate_xpath)[0])
|
||||||
|
|
||||||
if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
|
if re.match("^[0-9]+ minute(s|) ago$", publishedDate):
|
||||||
publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group()))
|
publishedDate = datetime.now() - timedelta(minutes=int(re.match(r'\d+', publishedDate).group())) # noqa
|
||||||
else:
|
else:
|
||||||
if re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$", publishedDate):
|
if re.match("^[0-9]+ hour(s|), [0-9]+ minute(s|) ago$",
|
||||||
|
publishedDate):
|
||||||
timeNumbers = re.findall(r'\d+', publishedDate)
|
timeNumbers = re.findall(r'\d+', publishedDate)
|
||||||
publishedDate = datetime.now() - timedelta(hours=int(timeNumbers[0])) - timedelta(minutes=int(timeNumbers[1]))
|
publishedDate = datetime.now()\
|
||||||
|
- timedelta(hours=int(timeNumbers[0]))\
|
||||||
|
- timedelta(minutes=int(timeNumbers[1]))
|
||||||
else:
|
else:
|
||||||
# TODO year in string possible?
|
# TODO year in string possible?
|
||||||
publishedDate = datetime.strptime(publishedDate,"%b %d %H:%M%p")
|
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)
|
||||||
|
|
||||||
results.append({'url': url, 'title': title, 'content': content,'publishedDate':publishedDate})
|
results.append({'url': url,
|
||||||
|
'title': title,
|
||||||
|
'content': content,
|
||||||
|
'publishedDate': publishedDate})
|
||||||
|
|
||||||
if not suggestion_xpath:
|
if not suggestion_xpath:
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -32,7 +32,7 @@ from flask import (
|
||||||
Flask, request, render_template, url_for, Response, make_response,
|
Flask, request, render_template, url_for, Response, make_response,
|
||||||
redirect, send_from_directory
|
redirect, send_from_directory
|
||||||
)
|
)
|
||||||
from flask.ext.babel import Babel, gettext, ngettext, format_date
|
from flask.ext.babel import Babel, gettext, format_date
|
||||||
from searx import settings, searx_dir
|
from searx import settings, searx_dir
|
||||||
from searx.engines import (
|
from searx.engines import (
|
||||||
search as do_search, categories, engines, get_engines_stats,
|
search as do_search, categories, engines, get_engines_stats,
|
||||||
|
@ -161,12 +161,12 @@ def index():
|
||||||
if 'publishedDate' in result:
|
if 'publishedDate' in result:
|
||||||
if result['publishedDate'] >= datetime.now() - timedelta(days=1):
|
if result['publishedDate'] >= datetime.now() - timedelta(days=1):
|
||||||
timedifference = datetime.now() - result['publishedDate']
|
timedifference = datetime.now() - result['publishedDate']
|
||||||
minutes = int((timedifference.seconds/60)%60)
|
minutes = int((timedifference.seconds / 60) % 60)
|
||||||
hours = int(timedifference.seconds/60/60)
|
hours = int(timedifference.seconds / 60 / 60)
|
||||||
if hours == 0:
|
if hours == 0:
|
||||||
result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes)
|
result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes) # noqa
|
||||||
else:
|
else:
|
||||||
result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes)
|
result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa
|
||||||
else:
|
else:
|
||||||
result['publishedDate'] = format_date(result['publishedDate'])
|
result['publishedDate'] = format_date(result['publishedDate'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue