summaryrefslogtreecommitdiff
path: root/searx/engines/searchcode_code.py
diff options
context:
space:
mode:
authorThomas Pointhuber <thomas.pointhuber@gmx.at>2014-12-22 16:26:45 +0100
committerThomas Pointhuber <thomas.pointhuber@gmx.at>2014-12-22 16:26:45 +0100
commitaf8dac93a8acff5042b7b399c38e348f0bdc32ad (patch)
treeefd4aab48cd0f97a01297d7870036633ad89dc92 /searx/engines/searchcode_code.py
parentd810763107733cec017b8688c0350dff527f2ed1 (diff)
downloadsearxng-af8dac93a8acff5042b7b399c38e348f0bdc32ad.tar.gz
searxng-af8dac93a8acff5042b7b399c38e348f0bdc32ad.zip
[enh] fix pep8, improve syntax highlighting
Diffstat (limited to 'searx/engines/searchcode_code.py')
-rw-r--r--searx/engines/searchcode_code.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/searx/engines/searchcode_code.py b/searx/engines/searchcode_code.py
index ac9647fcd..c71832f46 100644
--- a/searx/engines/searchcode_code.py
+++ b/searx/engines/searchcode_code.py
@@ -10,8 +10,7 @@
from urllib import urlencode
from json import loads
-import cgi
-import re
+
# engine dependent config
categories = ['it']
@@ -21,17 +20,10 @@ paging = True
url = 'https://searchcode.com/'
search_url = url+'api/codesearch_I/?{query}&p={pageno}'
-code_endings = {'c': 'c',
- 'css': 'css',
- 'cpp': 'cpp',
- 'c++': 'cpp',
+# special code-endings which are not recognised by the file ending
+code_endings = {'cs': 'c#',
'h': 'c',
- 'html': 'html',
- 'hpp': 'cpp',
- 'js': 'js',
- 'lua': 'lua',
- 'php': 'php',
- 'py': 'python'}
+ 'hpp': 'cpp'}
# do search-request
@@ -45,7 +37,7 @@ def request(query, params):
# get response from search-request
def response(resp):
results = []
-
+
search_results = loads(resp.text)
# parse results
@@ -53,12 +45,14 @@ def response(resp):
href = result['url']
title = "" + result['name'] + " - " + result['filename']
repo = result['repo']
-
+
lines = dict()
for line, code in result['lines'].items():
lines[int(line)] = code
- code_language = code_endings.get(result['filename'].split('.')[-1].lower(), None)
+ code_language = code_endings.get(
+ result['filename'].split('.')[-1].lower(),
+ result['filename'].split('.')[-1].lower())
# append result
results.append({'url': href,