Просмотр исходного кода

update github engine and add comments

Thomas Pointhuber 11 лет назад
Родитель
Сommit
334a286c18
2 измененных файлов: 30 добавлений и 3 удалений
  1. 30
    2
      searx/engines/github.py
  2. 0
    1
      searx/settings.yml

+ 30
- 2
searx/engines/github.py Просмотреть файл

@@ -1,31 +1,59 @@
1
+## Github (It)
2
+# 
3
+# @website     https://github.com/
4
+# @provide-api yes (https://developer.github.com/v3/)
5
+# 
6
+# @using-api   yes
7
+# @results     JSON
8
+# @stable      yes (using api)
9
+# @parse       url, title, content
10
+
1 11
 from urllib import urlencode
2 12
 from json import loads
3 13
 from cgi import escape
4 14
 
15
+# engine dependent config
5 16
 categories = ['it']
6 17
 
18
+# search-url
7 19
 search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'  # noqa
8 20
 
9 21
 accept_header = 'application/vnd.github.preview.text-match+json'
10 22
 
11 23
 
24
+# do search-request
12 25
 def request(query, params):
13 26
     params['url'] = search_url.format(query=urlencode({'q': query}))
27
+
14 28
     params['headers']['Accept'] = accept_header
29
+
15 30
     return params
16 31
 
17 32
 
33
+# get response from search-request
18 34
 def response(resp):
19 35
     results = []
36
+
20 37
     search_res = loads(resp.text)
38
+
39
+    # check if items are recieved
21 40
     if not 'items' in search_res:
22
-        return results
41
+        return []
42
+
43
+    # parse results
23 44
     for res in search_res['items']:
24 45
         title = res['name']
25 46
         url = res['html_url']
47
+
26 48
         if res['description']:
27 49
             content = escape(res['description'][:500])
28 50
         else:
29 51
             content = ''
30
-        results.append({'url': url, 'title': title, 'content': content})
52
+
53
+        # append result
54
+        results.append({'url': url,
55
+                        'title': title,
56
+                        'content': content})
57
+
58
+    # return results
31 59
     return results

+ 0
- 1
searx/settings.yml Просмотреть файл

@@ -66,7 +66,6 @@ engines:
66 66
 
67 67
   - name : github
68 68
     engine : github
69
-    categories : it
70 69
     shortcut : gh
71 70
 
72 71
   - name : google