summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-03-14 09:55:04 +0100
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-03-14 09:55:11 +0100
commitb88146d669b1196ed1efc4ae4108e238cfd7dbca (patch)
treea960b54ea6673059bbbf9fc25addde39ea5a8859 /searx/webapp.py
parenta559bad4884fa9dc60d44cd580812e1e2fedef80 (diff)
showing publishedDate for news
Diffstat (limited to 'searx/webapp.py')
-rw-r--r--searx/webapp.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index fdb6568b4..2f7f131c8 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -26,6 +26,7 @@ import json
import cStringIO
import os
+from datetime import datetime, timedelta
from itertools import chain
from flask import (
Flask, request, render_template, url_for, Response, make_response,
@@ -156,6 +157,17 @@ def index():
if engine in favicons:
result['favicon'] = engine
+ # TODO, check if timezone is calculated right
+ if 'publishedDate' in result:
+ if result['publishedDate'].date() == datetime.now().date():
+ timedifference = datetime.now()-result['publishedDate']
+ if timedifference.seconds < 60*60:
+ result['publishedDate'] = '{0:d} minutes ago'.format(timedifference.seconds/60)
+ else:
+ result['publishedDate'] = '{0:d} hours ago'.format(timedifference.seconds/60/60)
+ else:
+ result['publishedDate'] = result['publishedDate'].strftime('%d.%m.%Y')
+
if search.request_data.get('format') == 'json':
return Response(json.dumps({'query': search.query,
'results': search.results}),