Browse Source

[enh] api_key usage, disable the engine by default

potato 8 years ago
parent
commit
8c72a22757
2 changed files with 10 additions and 3 deletions
  1. 8
    2
      searx/engines/translated.py
  2. 2
    1
      searx/settings.yml

+ 8
- 2
searx/engines/translated.py View File

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

+ 2
- 1
searx/settings.yml View File

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