|
@@ -10,8 +10,7 @@
|
10
|
10
|
|
11
|
11
|
from urllib import urlencode
|
12
|
12
|
from json import loads
|
13
|
|
-import cgi
|
14
|
|
-import re
|
|
13
|
+
|
15
|
14
|
|
16
|
15
|
# engine dependent config
|
17
|
16
|
categories = ['it']
|
|
@@ -21,17 +20,10 @@ paging = True
|
21
|
20
|
url = 'https://searchcode.com/'
|
22
|
21
|
search_url = url+'api/codesearch_I/?{query}&p={pageno}'
|
23
|
22
|
|
24
|
|
-code_endings = {'c': 'c',
|
25
|
|
- 'css': 'css',
|
26
|
|
- 'cpp': 'cpp',
|
27
|
|
- 'c++': 'cpp',
|
|
23
|
+# special code-endings which are not recognised by the file ending
|
|
24
|
+code_endings = {'cs': 'c#',
|
28
|
25
|
'h': 'c',
|
29
|
|
- 'html': 'html',
|
30
|
|
- 'hpp': 'cpp',
|
31
|
|
- 'js': 'js',
|
32
|
|
- 'lua': 'lua',
|
33
|
|
- 'php': 'php',
|
34
|
|
- 'py': 'python'}
|
|
26
|
+ 'hpp': 'cpp'}
|
35
|
27
|
|
36
|
28
|
|
37
|
29
|
# do search-request
|
|
@@ -45,7 +37,7 @@ def request(query, params):
|
45
|
37
|
# get response from search-request
|
46
|
38
|
def response(resp):
|
47
|
39
|
results = []
|
48
|
|
-
|
|
40
|
+
|
49
|
41
|
search_results = loads(resp.text)
|
50
|
42
|
|
51
|
43
|
# parse results
|
|
@@ -53,12 +45,14 @@ def response(resp):
|
53
|
45
|
href = result['url']
|
54
|
46
|
title = "" + result['name'] + " - " + result['filename']
|
55
|
47
|
repo = result['repo']
|
56
|
|
-
|
|
48
|
+
|
57
|
49
|
lines = dict()
|
58
|
50
|
for line, code in result['lines'].items():
|
59
|
51
|
lines[int(line)] = code
|
60
|
52
|
|
61
|
|
- code_language = code_endings.get(result['filename'].split('.')[-1].lower(), None)
|
|
53
|
+ code_language = code_endings.get(
|
|
54
|
+ result['filename'].split('.')[-1].lower(),
|
|
55
|
+ result['filename'].split('.')[-1].lower())
|
62
|
56
|
|
63
|
57
|
# append result
|
64
|
58
|
results.append({'url': href,
|