summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2017-05-28 15:46:45 +0200
committerAlex <alex@al-f.net>2018-08-05 10:10:15 +0200
commit066bd916bf0c0344c978d2ea46cf9e9960841a61 (patch)
tree7daed2981af956a9abb099cbd3a4eb53cf87aacf /searx
parentd51732c0e5e89f86abfe68718277a2e21b190103 (diff)
downloadsearxng-066bd916bf0c0344c978d2ea46cf9e9960841a61.tar.gz
searxng-066bd916bf0c0344c978d2ea46cf9e9960841a61.zip
[mod] fetch firefox versions in a standalone script
Diffstat (limited to 'searx')
-rw-r--r--searx/data/useragents.json15
-rw-r--r--searx/utils.py28
2 files changed, 23 insertions, 20 deletions
diff --git a/searx/data/useragents.json b/searx/data/useragents.json
new file mode 100644
index 000000000..ba80ce885
--- /dev/null
+++ b/searx/data/useragents.json
@@ -0,0 +1,15 @@
+{
+ "os": [
+ "Windows NT 10; WOW64",
+ "X11; Linux x86_64"
+ ],
+ "ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}",
+ "versions": [
+ "59.0.2",
+ "59.0.1",
+ "59.0",
+ "58.0.2",
+ "58.0.1",
+ "58.0"
+ ]
+} \ No newline at end of file
diff --git a/searx/utils.py b/searx/utils.py
index bd6c3fe2f..f457284e3 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -10,8 +10,10 @@ from codecs import getincrementalencoder
from imp import load_source
from numbers import Number
from os.path import splitext, join
+from io import open
from random import choice
import sys
+import json
from searx import settings
from searx.version import VERSION_STRING
@@ -39,29 +41,11 @@ else:
logger = logger.getChild('utils')
-ua_versions = ('52.8.1',
- '53.0',
- '54.0',
- '55.0',
- '56.0',
- '57.0',
- '58.0',
- '59.0',
- '60.0.2')
-
-ua_os = ('Windows NT 6.3; WOW64',
- 'X11; Linux x86_64',
- 'X11; Linux x86')
-
-ua = "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}"
-
blocked_tags = ('script',
'style')
-
-def gen_useragent(os=None):
- # TODO
- return ua.format(os=os or choice(ua_os), version=choice(ua_versions))
+useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__))
+ + "/data/useragents.json", 'r', encoding='utf-8').read())
def searx_useragent():
@@ -70,6 +54,10 @@ def searx_useragent():
suffix=settings['outgoing'].get('useragent_suffix', ''))
+def gen_useragent():
+ return str(useragents['ua'].format(os=choice(useragents['os']), version=choice(useragents['versions'])))
+
+
def highlight_content(content, query):
if not content: