diff options
author | Alexandre Flament <alex@al-f.net> | 2020-10-05 13:50:33 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2020-10-07 10:29:34 +0200 |
commit | a9dc54bebc943000252975ef25ddcb51681fc284 (patch) | |
tree | 1cf83faca105df629ea06a3492884001d6b4d84c /searx/utils.py | |
parent | e30dc2f0ba481e033f127e5619d90cdc05d6db25 (diff) | |
download | searxng-a9dc54bebc943000252975ef25ddcb51681fc284.tar.gz searxng-a9dc54bebc943000252975ef25ddcb51681fc284.zip |
[mod] Add searx.data module
Instead of loading the data/*.json in different location,
load these files in the new searx.data module.
Diffstat (limited to 'searx/utils.py')
-rw-r--r-- | searx/utils.py | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/searx/utils.py b/searx/utils.py index db17feba9..1c10585cf 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- -import os import sys import re -import json import importlib from numbers import Number from os.path import splitext, join -from io import open from random import choice from html.parser import HTMLParser from urllib.parse import urljoin, urlparse, unquote @@ -18,6 +15,7 @@ from babel.core import get_global from searx import settings +from searx.data import USER_AGENTS from searx.version import VERSION_STRING from searx.languages import language_codes from searx import logger @@ -31,9 +29,6 @@ blocked_tags = ('script', ecma_unescape4_re = re.compile(r'%u([0-9a-fA-F]{4})', re.UNICODE) ecma_unescape2_re = re.compile(r'%([0-9a-fA-F]{2})', re.UNICODE) -useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__)) - + "/data/useragents.json", 'r', encoding='utf-8').read()) - xpath_cache = dict() lang_to_lc_cache = dict() @@ -50,7 +45,7 @@ def gen_useragent(os=None): See searx/data/useragents.json """ - return str(useragents['ua'].format(os=os or choice(useragents['os']), version=choice(useragents['versions']))) + return str(USER_AGENTS['ua'].format(os=os or choice(USER_AGENTS['os']), version=choice(USER_AGENTS['versions']))) class HTMLTextExtractorException(Exception): |