on master help sign in
fetch_firefox_version.py : compatible with Python 3 and minor fixes.
commit50c836864a9a7a765561d886b11f44d8cea0bce9 authorAlex <alex@al-f.net> dateSun 5 Aug 2018, 10:55 (8 years ago) parent066bd91
3 files changed+23−20
searx/data/useragents.json+9−10 searx/utils.py+2−2 utils/fetch_firefox_version.py+12−8
searx/data/useragents.json+9−10
@@ -1,15 +1,14 @@
11{
2+ "ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}",
3+ "versions": [
4+ "61.0.1",
5+ "61.0",
6+ "60.0.2",
7+ "60.0.1",
8+ "60.0"
9+ ],
210 "os": [
3− "Windows NT 10; WOW64",
11+ "Windows NT 10; WOW64",
412 "X11; Linux x86_64"
5− ],
6− "ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}",
7− "versions": [
8− "59.0.2",
9− "59.0.1",
10− "59.0",
11− "58.0.2",
12− "58.0.1",
13− "58.0"
1413 ]
1514}
searx/utils.py+2−2
@@ -54,8 +54,8 @@ def searx_useragent():
5454 suffix=settings['outgoing'].get('useragent_suffix', ''))
5555
5656
57−def gen_useragent():
58− return str(useragents['ua'].format(os=choice(useragents['os']), version=choice(useragents['versions'])))
57+def gen_useragent(os=None):
58+ return str(useragents['ua'].format(os=os or choice(useragents['os']), version=choice(useragents['versions'])))
5959
6060
6161def highlight_content(content, query):
utils/fetch_firefox_version.py+12−8
@@ -2,7 +2,7 @@
22
33# set path
44from sys import path
5−from os.path import realpath, dirname
5+from os.path import realpath, dirname, join
66path.append(realpath(dirname(realpath(__file__)) + '/../'))
77
88#
@@ -12,16 +12,17 @@ import re
1212from distutils.version import LooseVersion, StrictVersion
1313from lxml import html
1414from searx.url_utils import urlparse, urljoin
15+from searx import searx_dir
1516
1617URL = 'https://ftp.mozilla.org/pub/firefox/releases/'
1718RELEASE_PATH = '/pub/firefox/releases/'
1819
19−NORMAL_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?(esr)?$')
20+NORMAL_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?$')
2021# BETA_REGEX = re.compile('.*[0-9]b([0-9\-a-z]+)$')
2122# ESR_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?esr$')
2223
2324#
24−useragent = {
25+useragents = {
2526 "versions": (),
2627 "os": ('Windows NT 10; WOW64',
2728 'X11; Linux x86_64'),
@@ -57,13 +58,16 @@ def fetch_firefox_last_versions():
5758 major_list = (major_last, major_last - 1)
5859 for version in versions:
5960 major_current = version.version[0]
60− if major_current in major_list and 'esr' not in version.version:
61+ if major_current in major_list:
6162 result.append(version.vstring)
6263
6364 return result
6465
6566
66−useragent["versions"] = fetch_firefox_last_versions()
67−f = open("../searx/data/useragents.json", "wb")
68−json.dump(useragent, f, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8")
69−f.close()
67+def get_useragents_filename():
68+ return join(join(searx_dir, "data"), "useragents.json")
69+
70+
71+useragents["versions"] = fetch_firefox_last_versions()
72+with open(get_useragents_filename(), "w") as f:
73+ json.dump(useragents, f, indent=4, ensure_ascii=False)