update github engine and add comments
This commit is contained in:
		
							parent
							
								
									c5d83059d5
								
							
						
					
					
						commit
						334a286c18
					
				| @ -1,31 +1,59 @@ | |||||||
|  | ## Github (It) | ||||||
|  | #  | ||||||
|  | # @website     https://github.com/ | ||||||
|  | # @provide-api yes (https://developer.github.com/v3/) | ||||||
|  | #  | ||||||
|  | # @using-api   yes | ||||||
|  | # @results     JSON | ||||||
|  | # @stable      yes (using api) | ||||||
|  | # @parse       url, title, content | ||||||
|  | 
 | ||||||
| from urllib import urlencode | from urllib import urlencode | ||||||
| from json import loads | from json import loads | ||||||
| from cgi import escape | from cgi import escape | ||||||
| 
 | 
 | ||||||
|  | # engine dependent config | ||||||
| categories = ['it'] | categories = ['it'] | ||||||
| 
 | 
 | ||||||
|  | # search-url | ||||||
| search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'  # noqa | search_url = 'https://api.github.com/search/repositories?sort=stars&order=desc&{query}'  # noqa | ||||||
| 
 | 
 | ||||||
| accept_header = 'application/vnd.github.preview.text-match+json' | accept_header = 'application/vnd.github.preview.text-match+json' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # do search-request | ||||||
| def request(query, params): | def request(query, params): | ||||||
|     params['url'] = search_url.format(query=urlencode({'q': query})) |     params['url'] = search_url.format(query=urlencode({'q': query})) | ||||||
|  | 
 | ||||||
|     params['headers']['Accept'] = accept_header |     params['headers']['Accept'] = accept_header | ||||||
|  | 
 | ||||||
|     return params |     return params | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | # get response from search-request | ||||||
| def response(resp): | def response(resp): | ||||||
|     results = [] |     results = [] | ||||||
|  | 
 | ||||||
|     search_res = loads(resp.text) |     search_res = loads(resp.text) | ||||||
|  | 
 | ||||||
|  |     # check if items are recieved | ||||||
|     if not 'items' in search_res: |     if not 'items' in search_res: | ||||||
|         return results |         return [] | ||||||
|  | 
 | ||||||
|  |     # parse results | ||||||
|     for res in search_res['items']: |     for res in search_res['items']: | ||||||
|         title = res['name'] |         title = res['name'] | ||||||
|         url = res['html_url'] |         url = res['html_url'] | ||||||
|  | 
 | ||||||
|         if res['description']: |         if res['description']: | ||||||
|             content = escape(res['description'][:500]) |             content = escape(res['description'][:500]) | ||||||
|         else: |         else: | ||||||
|             content = '' |             content = '' | ||||||
|         results.append({'url': url, 'title': title, 'content': content}) | 
 | ||||||
|  |         # append result | ||||||
|  |         results.append({'url': url, | ||||||
|  |                         'title': title, | ||||||
|  |                         'content': content}) | ||||||
|  | 
 | ||||||
|  |     # return results | ||||||
|     return results |     return results | ||||||
|  | |||||||
| @ -66,7 +66,6 @@ engines: | |||||||
| 
 | 
 | ||||||
|   - name : github |   - name : github | ||||||
|     engine : github |     engine : github | ||||||
|     categories : it |  | ||||||
|     shortcut : gh |     shortcut : gh | ||||||
| 
 | 
 | ||||||
|   - name : google |   - name : google | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user