.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searchcode_code.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Searchcode (IT)
3
4
"""
5
6
from
json
import
loads
7
from
urllib.parse
import
urlencode
8
9
# about
10
about = {
11
"website"
:
'https://searchcode.com/'
,
12
"wikidata_id"
:
None
,
13
"official_api_documentation"
:
'https://searchcode.com/api/'
,
14
"use_official_api"
:
True
,
15
"require_api_key"
:
False
,
16
"results"
:
'JSON'
,
17
}
18
19
# engine dependent config
20
categories = [
'it'
]
21
search_api =
'https://searchcode.com/api/codesearch_I/?'
22
23
# special code-endings which are not recognised by the file ending
24
code_endings = {
'cs'
:
'c#'
,
'h'
:
'c'
,
'hpp'
:
'cpp'
,
'cxx'
:
'cpp'
}
25
26
# paging is broken in searchcode.com's API .. not sure it will ever been fixed
27
# paging = True
28
29
30
def
request
(query, params):
31
args = urlencode(
32
{
33
'q'
: query,
34
# paging is broken in searchcode.com's API
35
# 'p': params['pageno'] - 1,
36
# 'per_page': 10,
37
}
38
)
39
params[
'url'
] = search_api + args
40
logger.debug(
"query_url --> %s"
, params[
'url'
])
41
return
params
42
43
44
def
response
(resp):
45
results = []
46
47
search_results = loads(resp.text)
48
49
# parse results
50
for
result
in
search_results.get(
'results'
, []):
51
href = result[
'url'
]
52
title =
""
+ result[
'name'
] +
" - "
+ result[
'filename'
]
53
repo = result[
'repo'
]
54
55
lines = {}
56
for
line, code
in
result[
'lines'
].items():
57
lines[int(line)] = code
58
59
code_language = code_endings.get(
60
result[
'filename'
].split(
'.'
)[-1].lower(), result[
'filename'
].split(
'.'
)[-1].lower()
61
)
62
63
# append result
64
results.append(
65
{
66
'url'
: href,
67
'title'
: title,
68
'content'
:
''
,
69
'repository'
: repo,
70
'codelines'
: sorted(lines.items()),
71
'code_language'
: code_language,
72
'template'
:
'code.html'
,
73
}
74
)
75
76
# return results
77
return
results
searx.engines.searchcode_code.response
response(resp)
Definition
searchcode_code.py:44
searx.engines.searchcode_code.request
request(query, params)
Definition
searchcode_code.py:30
searxng
searx
engines
searchcode_code.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0