summaryrefslogtreecommitdiff
path: root/searx/engines/duckduckgo.py
diff options
context:
space:
mode:
authormarc <a01200356@itesm.mx>2016-11-05 20:51:38 -0600
committermarc <a01200356@itesm.mx>2016-12-13 19:58:10 -0600
commitf62ce21f50b540315a708ebfbf36878ddec9d1c4 (patch)
tree79f69b171e8d2d08fa30aa32a3592286622f9fcc /searx/engines/duckduckgo.py
parent92c6e88ad3e5ba57bd6e2ba64d0c38e8fd72ea09 (diff)
downloadsearxng-f62ce21f50b540315a708ebfbf36878ddec9d1c4.tar.gz
searxng-f62ce21f50b540315a708ebfbf36878ddec9d1c4.zip
[mod] fetch supported languages for several engines
utils/fetch_languages.py gets languages supported by each engine and generates engines_languages.json with each engine's supported language.
Diffstat (limited to 'searx/engines/duckduckgo.py')
-rw-r--r--searx/engines/duckduckgo.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py
index 3e1752dd0..d37d2778b 100644
--- a/searx/engines/duckduckgo.py
+++ b/searx/engines/duckduckgo.py
@@ -15,19 +15,15 @@
from urllib import urlencode
from lxml.html import fromstring
+from requests import get
+from json import loads
from searx.engines.xpath import extract_text
# engine dependent config
categories = ['general']
paging = True
language_support = True
-supported_languages = ["es-AR", "en-AU", "de-AT", "fr-BE", "nl-BE", "pt-BR", "bg-BG", "en-CA", "fr-CA", "ca-CT",
- "es-CL", "zh-CN", "es-CO", "hr-HR", "cs-CZ", "da-DK", "et-EE", "fi-FI", "fr-FR", "de-DE",
- "el-GR", "tzh-HK", "hu-HU", "en-IN", "id-ID", "en-ID", "en-IE", "he-IL", "it-IT", "jp-JP",
- "kr-KR", "es-XL", "lv-LV", "lt-LT", "ms-MY", "en-MY", "es-MX", "nl-NL", "en-NZ", "no-NO",
- "es-PE", "en-PH", "tl-PH", "pl-PL", "pt-PT", "ro-RO", "ru-RU", "ar-XA", "en-XA", "en-SG",
- "sk-SK", "sl-SL", "en-ZA", "es-ES", "ca-ES", "sv-SE", "de-CH", "fr-CH", "it-CH", "tzh-TW",
- "th-TH", "tr-TR", "uk-UA", "en-UK", "en-US", "es-US", "vi-VN"]
+supported_languages_url = 'https://duckduckgo.com/d2030.js'
time_range_support = True
# search-url
@@ -65,8 +61,6 @@ def request(query, params):
locale = 'xa' + params['language'].split('-')[0]
elif params['language'][-2:] == 'GB':
locale = 'uk' + params['language'].split('-')[0]
- elif params['language'] == 'es-419':
- locale = 'xl-es'
else:
locale = params['language'].split('-')
if len(locale) == 2:
@@ -120,3 +114,18 @@ def response(resp):
# return results
return results
+
+
+# get supported languages from their site
+def fetch_supported_languages():
+ response = get(supported_languages_url)
+
+ # response is a js file with regions as an embedded object
+ response_page = response.text
+ response_page = response_page[response_page.find('regions:{') + 8:]
+ response_page = response_page[:response_page.find('}') + 1]
+
+ regions_json = loads(response_page)
+ supported_languages = map((lambda x: x[3:] + '-' + x[:2].upper()), regions_json.keys())
+
+ return supported_languages