浏览代码

update engines_languages.json and languages.py

Also, fix fetch_languages.py so it can run on python3.
marc 7 年前
父节点
当前提交
44085e31d0

+ 1
- 1
searx/data/engines_languages.json
文件差异内容过多而无法显示
查看文件


+ 1
- 1
searx/engines/duckduckgo.py 查看文件

134
     regions_json = loads(response_page)
134
     regions_json = loads(response_page)
135
     supported_languages = map((lambda x: x[3:] + '-' + x[:2].upper()), regions_json.keys())
135
     supported_languages = map((lambda x: x[3:] + '-' + x[:2].upper()), regions_json.keys())
136
 
136
 
137
-    return supported_languages
137
+    return list(supported_languages)

+ 1
- 1
searx/engines/swisscows.py 查看文件

118
     dom = fromstring(resp.text)
118
     dom = fromstring(resp.text)
119
     options = dom.xpath('//div[@id="regions-popup"]//ul/li/a')
119
     options = dom.xpath('//div[@id="regions-popup"]//ul/li/a')
120
     for option in options:
120
     for option in options:
121
-        code = option.xpath('./@data-val')[0]
121
+        code = option.xpath('./@data-search-language')[0]
122
         if code.startswith('nb-'):
122
         if code.startswith('nb-'):
123
             code = code.replace('nb', 'no', 1)
123
             code = code.replace('nb', 'no', 1)
124
         supported_languages.append(code)
124
         supported_languages.append(code)

+ 8
- 10
searx/languages.py 查看文件

5
 language_codes = (
5
 language_codes = (
6
     (u"ar-SA", u"العربية", u"", u"Arabic"),
6
     (u"ar-SA", u"العربية", u"", u"Arabic"),
7
     (u"bg-BG", u"Български", u"", u"Bulgarian"),
7
     (u"bg-BG", u"Български", u"", u"Bulgarian"),
8
+    (u"ca", u"Català", u"", u"Catalan"),
9
+    (u"ca-AD", u"Català", u"Andorra", u"Catalan"),
10
+    (u"ca-CT", u"Català", u"", u"Catalan"),
11
+    (u"ca-ES", u"Català", u"Espanya", u"Catalan"),
12
+    (u"ca-FR", u"Català", u"França", u"Catalan"),
8
     (u"cs-CZ", u"Čeština", u"", u"Czech"),
13
     (u"cs-CZ", u"Čeština", u"", u"Czech"),
9
     (u"da-DK", u"Dansk", u"", u"Danish"),
14
     (u"da-DK", u"Dansk", u"", u"Danish"),
10
     (u"de", u"Deutsch", u"", u"German"),
15
     (u"de", u"Deutsch", u"", u"German"),
15
     (u"en", u"English", u"", u"English"),
20
     (u"en", u"English", u"", u"English"),
16
     (u"en-AU", u"English", u"Australia", u"English"),
21
     (u"en-AU", u"English", u"Australia", u"English"),
17
     (u"en-CA", u"English", u"Canada", u"English"),
22
     (u"en-CA", u"English", u"Canada", u"English"),
18
-    (u"en-CY", u"English", u"Cyprus", u"English"),
19
     (u"en-GB", u"English", u"United Kingdom", u"English"),
23
     (u"en-GB", u"English", u"United Kingdom", u"English"),
20
-    (u"en-GD", u"English", u"Grenada", u"English"),
21
     (u"en-ID", u"English", u"Indonesia", u"English"),
24
     (u"en-ID", u"English", u"Indonesia", u"English"),
22
     (u"en-IE", u"English", u"Ireland", u"English"),
25
     (u"en-IE", u"English", u"Ireland", u"English"),
23
     (u"en-IN", u"English", u"India", u"English"),
26
     (u"en-IN", u"English", u"India", u"English"),
28
     (u"en-US", u"English", u"United States", u"English"),
31
     (u"en-US", u"English", u"United States", u"English"),
29
     (u"en-ZA", u"English", u"South Africa", u"English"),
32
     (u"en-ZA", u"English", u"South Africa", u"English"),
30
     (u"es", u"Español", u"", u"Spanish"),
33
     (u"es", u"Español", u"", u"Spanish"),
34
+    (u"es-AD", u"Español", u"Andorra", u"Spanish"),
31
     (u"es-AR", u"Español", u"Argentina", u"Spanish"),
35
     (u"es-AR", u"Español", u"Argentina", u"Spanish"),
32
     (u"es-CL", u"Español", u"Chile", u"Spanish"),
36
     (u"es-CL", u"Español", u"Chile", u"Spanish"),
33
     (u"es-CO", u"Español", u"Colombia", u"Spanish"),
37
     (u"es-CO", u"Español", u"Colombia", u"Spanish"),
38
     (u"et-EE", u"Eesti", u"", u"Estonian"),
42
     (u"et-EE", u"Eesti", u"", u"Estonian"),
39
     (u"fi-FI", u"Suomi", u"", u"Finnish"),
43
     (u"fi-FI", u"Suomi", u"", u"Finnish"),
40
     (u"fr", u"Français", u"", u"French"),
44
     (u"fr", u"Français", u"", u"French"),
45
+    (u"fr-AD", u"Français", u"Andorre", u"French"),
41
     (u"fr-BE", u"Français", u"Belgique", u"French"),
46
     (u"fr-BE", u"Français", u"Belgique", u"French"),
42
     (u"fr-CA", u"Français", u"Canada", u"French"),
47
     (u"fr-CA", u"Français", u"Canada", u"French"),
43
     (u"fr-CH", u"Français", u"Suisse", u"French"),
48
     (u"fr-CH", u"Français", u"Suisse", u"French"),
44
     (u"fr-FR", u"Français", u"France", u"French"),
49
     (u"fr-FR", u"Français", u"France", u"French"),
45
     (u"he-IL", u"עברית", u"", u"Hebrew"),
50
     (u"he-IL", u"עברית", u"", u"Hebrew"),
46
-    (u"hr-HR", u"Hrvatski", u"", u"Croatian"),
47
     (u"hu-HU", u"Magyar", u"", u"Hungarian"),
51
     (u"hu-HU", u"Magyar", u"", u"Hungarian"),
48
-    (u"id-ID", u"Bahasa Indonesia", u"", u"Indonesian"),
49
     (u"it", u"Italiano", u"", u"Italian"),
52
     (u"it", u"Italiano", u"", u"Italian"),
50
     (u"it-CH", u"Italiano", u"Svizzera", u"Italian"),
53
     (u"it-CH", u"Italiano", u"Svizzera", u"Italian"),
51
     (u"it-IT", u"Italiano", u"Italia", u"Italian"),
54
     (u"it-IT", u"Italiano", u"Italia", u"Italian"),
52
     (u"ja-JP", u"日本語", u"", u"Japanese"),
55
     (u"ja-JP", u"日本語", u"", u"Japanese"),
53
     (u"ko-KR", u"한국어", u"", u"Korean"),
56
     (u"ko-KR", u"한국어", u"", u"Korean"),
54
-    (u"lt-LT", u"Lietuvių", u"", u"Lithuanian"),
55
-    (u"lv-LV", u"Latviešu", u"", u"Latvian"),
56
-    (u"ms-MY", u"Bahasa Melayu", u"", u"Malay"),
57
     (u"nl", u"Nederlands", u"", u"Dutch"),
57
     (u"nl", u"Nederlands", u"", u"Dutch"),
58
     (u"nl-BE", u"Nederlands", u"België", u"Dutch"),
58
     (u"nl-BE", u"Nederlands", u"België", u"Dutch"),
59
     (u"nl-NL", u"Nederlands", u"Nederland", u"Dutch"),
59
     (u"nl-NL", u"Nederlands", u"Nederland", u"Dutch"),
60
     (u"no-NO", u"Norsk", u"", u"Norwegian"),
60
     (u"no-NO", u"Norsk", u"", u"Norwegian"),
61
     (u"pl-PL", u"Polski", u"", u"Polish"),
61
     (u"pl-PL", u"Polski", u"", u"Polish"),
62
     (u"pt", u"Português", u"", u"Portuguese"),
62
     (u"pt", u"Português", u"", u"Portuguese"),
63
+    (u"pt-AD", u"Português", u"Andorra", u"Portuguese"),
63
     (u"pt-BR", u"Português", u"Brasil", u"Portuguese"),
64
     (u"pt-BR", u"Português", u"Brasil", u"Portuguese"),
64
     (u"pt-PT", u"Português", u"Portugal", u"Portuguese"),
65
     (u"pt-PT", u"Português", u"Portugal", u"Portuguese"),
65
     (u"ro-RO", u"Română", u"", u"Romanian"),
66
     (u"ro-RO", u"Română", u"", u"Romanian"),
66
     (u"ru-RU", u"Русский", u"", u"Russian"),
67
     (u"ru-RU", u"Русский", u"", u"Russian"),
67
-    (u"sk-SK", u"Slovenčina", u"", u"Slovak"),
68
-    (u"sl", u"Slovenščina", u"", u"Slovenian"),
69
     (u"sv-SE", u"Svenska", u"", u"Swedish"),
68
     (u"sv-SE", u"Svenska", u"", u"Swedish"),
70
     (u"th-TH", u"ไทย", u"", u"Thai"),
69
     (u"th-TH", u"ไทย", u"", u"Thai"),
71
     (u"tr-TR", u"Türkçe", u"", u"Turkish"),
70
     (u"tr-TR", u"Türkçe", u"", u"Turkish"),
72
-    (u"vi-VN", u"Tiếng Việt", u"", u"Vietnamese"),
73
     (u"zh", u"中文", u"", u"Chinese"),
71
     (u"zh", u"中文", u"", u"Chinese"),
74
     (u"zh-CN", u"中文", u"中国", u"Chinese"),
72
     (u"zh-CN", u"中文", u"中国", u"Chinese"),
75
     (u"zh-HK", u"中文", u"香港", u"Chinese"),
73
     (u"zh-HK", u"中文", u"香港", u"Chinese"),

+ 3
- 3
tests/unit/engines/test_swisscows.py 查看文件

139
             <div id="regions-popup">
139
             <div id="regions-popup">
140
                 <div>
140
                 <div>
141
                     <ul>
141
                     <ul>
142
-                        <li><a data-val="browser"></a></li>
143
-                        <li><a data-val="de-CH"></a></li>
144
-                        <li><a data-val="fr-CH"></a></li>
142
+                        <li><a data-search-language="browser"></a></li>
143
+                        <li><a data-search-language="de-CH"></a></li>
144
+                        <li><a data-search-language="fr-CH"></a></li>
145
                     </ul>
145
                     </ul>
146
                 </div>
146
                 </div>
147
             </div>
147
             </div>

+ 8
- 8
utils/fetch_languages.py 查看文件

8
 # are written in current directory to avoid overwriting in case something goes wrong.
8
 # are written in current directory to avoid overwriting in case something goes wrong.
9
 
9
 
10
 from requests import get
10
 from requests import get
11
-from urllib import urlencode
12
 from lxml.html import fromstring
11
 from lxml.html import fromstring
13
-from json import loads, dumps
12
+from json import loads, dump
14
 import io
13
 import io
15
 from sys import path
14
 from sys import path
16
 path.append('../searx')  # noqa
15
 path.append('../searx')  # noqa
17
 from searx import settings
16
 from searx import settings
17
+from searx.url_utils import urlencode
18
 from searx.engines import initialize_engines, engines
18
 from searx.engines import initialize_engines, engines
19
 
19
 
20
 # Geonames API for country names.
20
 # Geonames API for country names.
70
     json = loads(response.text)
70
     json = loads(response.text)
71
     content = json.get('geonames', None)
71
     content = json.get('geonames', None)
72
     if content is None or len(content) != 1:
72
     if content is None or len(content) != 1:
73
-        print "No country name found for " + locale[0] + "-" + locale[1]
73
+        print("No country name found for " + locale[0] + "-" + locale[1])
74
         return ''
74
         return ''
75
 
75
 
76
     return content[0].get('countryName', '')
76
     return content[0].get('countryName', '')
84
             try:
84
             try:
85
                 engines_languages[engine_name] = engines[engine_name].fetch_supported_languages()
85
                 engines_languages[engine_name] = engines[engine_name].fetch_supported_languages()
86
             except Exception as e:
86
             except Exception as e:
87
-                print e
87
+                print(e)
88
 
88
 
89
     # write json file
89
     # write json file
90
     with io.open(engines_languages_file, "w", encoding="utf-8") as f:
90
     with io.open(engines_languages_file, "w", encoding="utf-8") as f:
91
-        f.write(unicode(dumps(engines_languages, ensure_ascii=False, encoding="utf-8")))
91
+        dump(engines_languages, f, ensure_ascii=False)
92
 
92
 
93
 
93
 
94
 # Join all language lists.
94
 # Join all language lists.
97
     global languages
97
     global languages
98
     # include wikipedia first for more accurate language names
98
     # include wikipedia first for more accurate language names
99
     languages = {code: lang for code, lang
99
     languages = {code: lang for code, lang
100
-                 in engines_languages['wikipedia'].iteritems()
100
+                 in engines_languages['wikipedia'].items()
101
                  if valid_code(code)}
101
                  if valid_code(code)}
102
 
102
 
103
     for engine_name in engines_languages:
103
     for engine_name in engines_languages:
121
     # filter list to include only languages supported by most engines
121
     # filter list to include only languages supported by most engines
122
     min_supported_engines = int(0.70 * len(engines_languages))
122
     min_supported_engines = int(0.70 * len(engines_languages))
123
     languages = {code: lang for code, lang
123
     languages = {code: lang for code, lang
124
-                 in languages.iteritems()
124
+                 in languages.items()
125
                  if len(lang.get('counter', [])) >= min_supported_engines or
125
                  if len(lang.get('counter', [])) >= min_supported_engines or
126
                  len(languages.get(code.split('-')[0], {}).get('counter', [])) >= min_supported_engines}
126
                  len(languages.get(code.split('-')[0], {}).get('counter', [])) >= min_supported_engines}
127
 
127
 
165
 
165
 
166
 # Write languages.py.
166
 # Write languages.py.
167
 def write_languages_file():
167
 def write_languages_file():
168
-    new_file = open(languages_file, 'w')
168
+    new_file = open(languages_file, 'wb')
169
     file_content = '# -*- coding: utf-8 -*-\n'\
169
     file_content = '# -*- coding: utf-8 -*-\n'\
170
                    + '# list of language codes\n'\
170
                    + '# list of language codes\n'\
171
                    + '# this file is generated automatically by utils/update_search_languages.py\n'\
171
                    + '# this file is generated automatically by utils/update_search_languages.py\n'\