From b88146d669b1196ed1efc4ae4108e238cfd7dbca Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Fri, 14 Mar 2014 09:55:04 +0100 Subject: showing publishedDate for news --- searx/webapp.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'searx/webapp.py') 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}), -- cgit v1.2.3 From 7a922b2ab8464f32ebed03d4c2b652159891fdc7 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Fri, 14 Mar 2014 10:55:52 +0100 Subject: adding translations support for publish-date --- searx/webapp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 2f7f131c8..9d1221fa0 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -32,7 +32,7 @@ from flask import ( Flask, request, render_template, url_for, Response, make_response, redirect, send_from_directory ) -from flask.ext.babel import Babel +from flask.ext.babel import Babel, gettext, ngettext, format_date from searx import settings, searx_dir from searx.engines import ( search as do_search, categories, engines, get_engines_stats, @@ -162,11 +162,11 @@ def index(): 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) + result['publishedDate'] = gettext(u'{0:d} minutes ago').format(timedifference.seconds/60) else: - result['publishedDate'] = '{0:d} hours ago'.format(timedifference.seconds/60/60) + result['publishedDate'] = gettext(u'{0:d} hours ago').format(timedifference.seconds/60/60) else: - result['publishedDate'] = result['publishedDate'].strftime('%d.%m.%Y') + result['publishedDate'] = format_date(result['publishedDate']) if search.request_data.get('format') == 'json': return Response(json.dumps({'query': search.query, -- cgit v1.2.3 From 794165d19cbf91b62d45e93c9a2f387346b89c7b Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 15 Mar 2014 19:13:57 +0100 Subject: improve published Date output --- searx/webapp.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 9d1221fa0..5cc059044 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -161,10 +161,24 @@ def index(): if 'publishedDate' in result: if result['publishedDate'].date() == datetime.now().date(): timedifference = datetime.now()-result['publishedDate'] - if timedifference.seconds < 60*60: - result['publishedDate'] = gettext(u'{0:d} minutes ago').format(timedifference.seconds/60) + minutes = int((timedifference.seconds/60)%60) + hours = int(timedifference.seconds/60/60) + if hours == 0: + if minutes == 1: + result['publishedDate'] = gettext(u'1 minute ago') + else: + result['publishedDate'] = gettext(u'{minutes} minutes ago').format(minutes=minutes) else: - result['publishedDate'] = gettext(u'{0:d} hours ago').format(timedifference.seconds/60/60) + if hours == 1: + if minutes == 1: + result['publishedDate'] = gettext(u'1 hour, 1 minute ago') + else: + result['publishedDate'] = gettext(u'1 hour, {minutes} minutes ago').format(minutes=minutes) + else: + if minutes == 1: + result['publishedDate'] = gettext(u'{hours} hours, 1 minutes ago').format(hours=hours) + else: + result['publishedDate'] = gettext(u'{hours} hours, {minutes} minutes ago').format(hours=hours, minutes=minutes) else: result['publishedDate'] = format_date(result['publishedDate']) -- cgit v1.2.3 From ef2b1b7515fbc029d566ab1afb80429007983fbb Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 15 Mar 2014 19:31:34 +0100 Subject: fix little bug --- searx/webapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 5cc059044..54061a462 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -159,8 +159,8 @@ def index(): # TODO, check if timezone is calculated right if 'publishedDate' in result: - if result['publishedDate'].date() == datetime.now().date(): - timedifference = datetime.now()-result['publishedDate'] + if result['publishedDate'] >= datetime.now() - timedelta(days=1): + timedifference = datetime.now() - result['publishedDate'] minutes = int((timedifference.seconds/60)%60) hours = int(timedifference.seconds/60/60) if hours == 0: -- cgit v1.2.3 From d54ef01898a1bd289560ae757593df9f43fba7bc Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sat, 15 Mar 2014 19:41:54 +0100 Subject: simplify publish Date formating --- searx/webapp.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 54061a462..251d5672b 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -164,21 +164,9 @@ def index(): minutes = int((timedifference.seconds/60)%60) hours = int(timedifference.seconds/60/60) if hours == 0: - if minutes == 1: - result['publishedDate'] = gettext(u'1 minute ago') - else: - result['publishedDate'] = gettext(u'{minutes} minutes ago').format(minutes=minutes) + result['publishedDate'] = gettext(u'{minutes} minute(s) ago').format(minutes=minutes) else: - if hours == 1: - if minutes == 1: - result['publishedDate'] = gettext(u'1 hour, 1 minute ago') - else: - result['publishedDate'] = gettext(u'1 hour, {minutes} minutes ago').format(minutes=minutes) - else: - if minutes == 1: - result['publishedDate'] = gettext(u'{hours} hours, 1 minutes ago').format(hours=hours) - else: - result['publishedDate'] = gettext(u'{hours} hours, {minutes} minutes ago').format(hours=hours, minutes=minutes) + result['publishedDate'] = gettext(u'{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes) else: result['publishedDate'] = format_date(result['publishedDate']) -- cgit v1.2.3