summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorjibe-b <user701@orange.fr>2016-03-29 11:59:16 +0200
committerjibe-b <user701@orange.fr>2016-03-29 16:17:17 +0200
commit092e15cc1db2faa6c2fffb6163c5147d386bf948 (patch)
tree3833fa6ca9d1b1777d584eeddb782f207b2fe726 /searx/webapp.py
parent71de593a5b9025e360da32813e9efeaeaa4992b2 (diff)
downloadsearxng-092e15cc1db2faa6c2fffb6163c5147d386bf948.tar.gz
searxng-092e15cc1db2faa6c2fffb6163c5147d386bf948.zip
[enh] Add BASE engine in category Science. Basic and advanced search.
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index 66ba65a29..2b665d962 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -408,17 +408,21 @@ def index():
# TODO, check if timezone is calculated right
if 'publishedDate' in result:
- result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')
- if result['publishedDate'].replace(tzinfo=None) >= datetime.now() - timedelta(days=1):
- timedifference = datetime.now() - result['publishedDate'].replace(tzinfo=None)
- minutes = int((timedifference.seconds / 60) % 60)
- hours = int(timedifference.seconds / 60 / 60)
- if hours == 0:
- result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes)
- else:
- result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa
+ try: # test if publishedDate >= 1900 (datetime module bug)
+ result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')
+ except ValueError:
+ result['publishedDate'] = None
else:
- result['publishedDate'] = format_date(result['publishedDate'])
+ if result['publishedDate'].replace(tzinfo=None) >= datetime.now() - timedelta(days=1):
+ timedifference = datetime.now() - result['publishedDate'].replace(tzinfo=None)
+ minutes = int((timedifference.seconds / 60) % 60)
+ hours = int(timedifference.seconds / 60 / 60)
+ if hours == 0:
+ result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes)
+ else:
+ result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) # noqa
+ else:
+ result['publishedDate'] = format_date(result['publishedDate'])
if search.request_data.get('format') == 'json':
return Response(json.dumps({'query': search.query,