|
@@ -0,0 +1,69 @@
|
|
1
|
+#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+# set path
|
|
4
|
+from sys import path
|
|
5
|
+from os.path import realpath, dirname
|
|
6
|
+path.append(realpath(dirname(realpath(__file__)) + '/../'))
|
|
7
|
+
|
|
8
|
+#
|
|
9
|
+import json
|
|
10
|
+import requests
|
|
11
|
+import re
|
|
12
|
+from distutils.version import LooseVersion, StrictVersion
|
|
13
|
+from lxml import html
|
|
14
|
+from searx.url_utils import urlparse, urljoin
|
|
15
|
+
|
|
16
|
+URL = 'https://ftp.mozilla.org/pub/firefox/releases/'
|
|
17
|
+RELEASE_PATH = '/pub/firefox/releases/'
|
|
18
|
+
|
|
19
|
+NORMAL_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?(esr)?$')
|
|
20
|
+# BETA_REGEX = re.compile('.*[0-9]b([0-9\-a-z]+)$')
|
|
21
|
+# ESR_REGEX = re.compile('^[0-9]+\.[0-9](\.[0-9])?esr$')
|
|
22
|
+
|
|
23
|
+#
|
|
24
|
+useragent = {
|
|
25
|
+ "versions": (),
|
|
26
|
+ "os": ('Windows NT 10; WOW64',
|
|
27
|
+ 'X11; Linux x86_64'),
|
|
28
|
+ "ua": "Mozilla/5.0 ({os}; rv:{version}) Gecko/20100101 Firefox/{version}"
|
|
29
|
+}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+def fetch_firefox_versions():
|
|
33
|
+ resp = requests.get(URL, timeout=2.0)
|
|
34
|
+ if resp.status_code != 200:
|
|
35
|
+ raise Exception("Error fetching firefox versions, HTTP code " + resp.status_code)
|
|
36
|
+ else:
|
|
37
|
+ dom = html.fromstring(resp.text)
|
|
38
|
+ versions = []
|
|
39
|
+
|
|
40
|
+ for link in dom.xpath('//a/@href'):
|
|
41
|
+ url = urlparse(urljoin(URL, link))
|
|
42
|
+ path = url.path
|
|
43
|
+ if path.startswith(RELEASE_PATH):
|
|
44
|
+ version = path[len(RELEASE_PATH):-1]
|
|
45
|
+ if NORMAL_REGEX.match(version):
|
|
46
|
+ versions.append(LooseVersion(version))
|
|
47
|
+
|
|
48
|
+ list.sort(versions, reverse=True)
|
|
49
|
+ return versions
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+def fetch_firefox_last_versions():
|
|
53
|
+ versions = fetch_firefox_versions()
|
|
54
|
+
|
|
55
|
+ result = []
|
|
56
|
+ major_last = versions[0].version[0]
|
|
57
|
+ major_list = (major_last, major_last - 1)
|
|
58
|
+ for version in versions:
|
|
59
|
+ major_current = version.version[0]
|
|
60
|
+ if major_current in major_list and 'esr' not in version.version:
|
|
61
|
+ result.append(version.vstring)
|
|
62
|
+
|
|
63
|
+ return result
|
|
64
|
+
|
|
65
|
+
|
|
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()
|