SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
Add searx.webutils.searxng_format_date
Alexandre FLAMENTa96f503d7b48
diff --git a/searx/webapp.py b/searx/webapp.pyindex bd76cc534..e6bda42be 100755--- a/searx/webapp.py+++ b/searx/webapp.py@@ -12,7 +12,6 @@ import osimport sysimport base64-from datetime import datetime, timedeltafrom timeit import default_timerfrom html import escapefrom io import StringIO@@ -45,7 +44,6 @@ from flask.json import jsonifyfrom flask_babel import (Babel,gettext,- format_date,format_decimal,)@@ -79,6 +77,7 @@ from searx.webutils import (is_hmac_of,is_flask_run_cmdline,group_engines_in_tab,+ searxng_format_date,)from searx.webadapter import (get_search_query_from_webapp,@@ -718,25 +717,13 @@ def search():if 'url' in result:result['pretty_url'] = prettify_url(result['url'])- # TODO, check if timezone is calculated right # pylint: disable=fixmeif result.get('publishedDate'): # do not try to get a date from an empty string or a None typetry: # test if publishedDate >= 1900 (datetime module bug)result['pubdate'] = result['publishedDate'].strftime('%Y-%m-%d %H:%M:%S%z')except ValueError:result['publishedDate'] = Noneelse:- 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('{minutes} minute(s) ago').format(minutes=minutes)- else:- result['publishedDate'] = gettext('{hours} hour(s), {minutes} minute(s) ago').format(- hours=hours, minutes=minutes- )- else:- result['publishedDate'] = format_date(result['publishedDate'])+ result['publishedDate'] = searxng_format_date(result['publishedDate'])# set result['open_group'] = True when the template changes from the previous result# set result['close_group'] = True when the template changes on the next resultdiff --git a/searx/webutils.py b/searx/webutils.pyindex b18fd5c6a..f084fe9d3 100644--- a/searx/webutils.py+++ b/searx/webutils.py@@ -7,11 +7,14 @@ import hmacimport reimport inspectimport itertools+from datetime import datetime, timedeltafrom typing import Iterable, List, Tuple, Dictfrom io import StringIOfrom codecs import getincrementalencoder+from flask_babel import gettext, format_date+from searx import logger, settingsfrom searx.engines import Engine, OTHER_CATEGORY@@ -138,6 +141,22 @@ def highlight_content(content, query):return content+def searxng_format_date(dt: datetime): # pylint: disable=invalid-name+ # TODO, check if timezone is calculated right # pylint: disable=fixme+ d = dt.date()+ t = dt.time()+ if d.month == 1 and d.day == 1 and t.hour == 0 and t.minute == 0 and t.second == 0:+ return str(d.year)+ if dt.replace(tzinfo=None) >= datetime.now() - timedelta(days=1):+ timedifference = datetime.now() - dt.replace(tzinfo=None)+ minutes = int((timedifference.seconds / 60) % 60)+ hours = int(timedifference.seconds / 60 / 60)+ if hours == 0:+ return gettext('{minutes} minute(s) ago').format(minutes=minutes)+ return gettext('{hours} hour(s), {minutes} minute(s) ago').format(hours=hours, minutes=minutes)+ return format_date(dt)++def is_flask_run_cmdline():"""Check if the application was started using "flask run" command line