Procházet zdrojové kódy

[enh] add asksteem engine - closes #1163

Adam Tauber před 6 roky
rodič
revize
b4c657d227
2 změnil soubory, kde provedl 47 přidání a 0 odebrání
  1. 43
    0
      searx/engines/asksteem.py
  2. 4
    0
      searx/settings.yml

+ 43
- 0
searx/engines/asksteem.py Zobrazit soubor

@@ -0,0 +1,43 @@
1
+"""
2
+ Asksteem (general)
3
+
4
+ @website     https://asksteem.com/
5
+ @provide-api yes
6
+
7
+ @using-api   yes
8
+ @results     JSON (https://github.com/Hoxly/asksteem-docs/wiki)
9
+ @stable      yes
10
+ @parse       url, title, content
11
+"""
12
+
13
+from json import loads
14
+from searx.url_utils import urlencode
15
+
16
+# engine dependent config
17
+categories = ['general']
18
+paging = True
19
+language_support = False
20
+disabled = True
21
+
22
+# search-url
23
+search_url = 'https://api.asksteem.com/search?{params}'
24
+result_url = 'https://steemit.com/@{author}/{title}'
25
+
26
+
27
+# do search-request
28
+def request(query, params):
29
+    url = search_url.format(params=urlencode({'q': query, 'pg': params['pageno']}))
30
+    params['url'] = url
31
+    return params
32
+
33
+# get response from search-request
34
+def response(resp):
35
+    json = loads(resp.text)
36
+
37
+    results = []
38
+
39
+    for result in json.get('results', []):
40
+        results.append({'url': result_url.format(author=result['author'], title=result['permlink']),
41
+                        'title': result['title'],
42
+                        'content': result['summary']})
43
+    return results

+ 4
- 0
searx/settings.yml Zobrazit soubor

@@ -66,6 +66,10 @@ engines:
66 66
     categories : science
67 67
     timeout : 4.0
68 68
 
69
+  - name : asksteem
70
+    engine : asksteem
71
+    shortcut : as
72
+
69 73
   - name : base
70 74
     engine : base
71 75
     shortcut : bs