浏览代码

[enh] api_key usage, disable the engine by default

potato 8 年前
父节点
当前提交
8c72a22757
共有 2 个文件被更改,包括 10 次插入3 次删除
  1. 8
    2
      searx/engines/translated.py
  2. 2
    1
      searx/settings.yml

+ 8
- 2
searx/engines/translated.py 查看文件

@@ -7,11 +7,12 @@ from searx.languages import language_codes
7 7
 
8 8
 categories = ['general']
9 9
 url = 'http://api.mymemory.translated.net/get?q={query}' \
10
-      '&langpair={from_lang}|{to_lang}'
10
+      '&langpair={from_lang}|{to_lang}{key}'
11 11
 web_url = 'http://mymemory.translated.net/en/{from_lang}/{to_lang}/{query}'
12 12
 weight = 100
13 13
 
14 14
 parser_re = re.compile(u'.*?([a-z]+)-([a-z]+) (.{2,})$', re.I)
15
+api_key = ''
15 16
 
16 17
 
17 18
 def is_valid_lang(lang):
@@ -41,9 +42,14 @@ def request(query, params):
41 42
     if not from_lang or not to_lang:
42 43
         return params
43 44
 
45
+    if api_key:
46
+        key_form = '&key=' + api_key
47
+    else:
48
+        key_form = ''
44 49
     params['url'] = url.format(from_lang=from_lang[1],
45 50
                                to_lang=to_lang[1],
46
-                               query=query)
51
+                               query=query,
52
+                               key=key_form)
47 53
     params['query'] = query
48 54
     params['from_lang'] = from_lang
49 55
     params['to_lang'] = to_lang

+ 2
- 1
searx/settings.yml 查看文件

@@ -7,7 +7,7 @@ search:
7 7
     autocomplete : "" # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default
8 8
 
9 9
 server:
10
-    port : 8888
10
+    port : 8889
11 11
     bind_address : "127.0.0.1" # address to listen on
12 12
     secret_key : "ultrasecretkey" # change this!
13 13
     base_url : False # Set custom base_url. Possible values: False or "https://your.custom.host/location/"
@@ -503,6 +503,7 @@ engines:
503 503
     engine : translated
504 504
     shortcut : tl
505 505
     timeout : 5.0
506
+    disabled : True
506 507
     # You can use without an API key, but you are limited to 1000 words/day
507 508
     # See : http://mymemory.translated.net/doc/usagelimits.php
508 509
     # api_key : ''