.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
stackexchange.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Stack Exchange API v2.3
3
4
* https://api.stackexchange.com/
5
6
"""
7
8
import
html
9
from
json
import
loads
10
from
urllib.parse
import
urlencode
11
12
about = {
13
"website"
:
'https://stackexchange.com'
,
14
"wikidata_id"
:
'Q3495447'
,
15
"official_api_documentation"
:
'https://api.stackexchange.com/docs'
,
16
"use_official_api"
:
True
,
17
"require_api_key"
:
False
,
18
"results"
:
'JSON'
,
19
}
20
21
paging =
True
22
pagesize = 10
23
24
api_site =
'stackoverflow'
25
api_sort =
'activity'
26
api_order =
'desc'
27
28
# https://api.stackexchange.com/docs/advanced-search
29
search_api =
'https://api.stackexchange.com/2.3/search/advanced?'
30
31
32
def
request
(query, params):
33
34
args = urlencode(
35
{
36
'q'
: query,
37
'page'
: params[
'pageno'
],
38
'pagesize'
: pagesize,
39
'site'
: api_site,
40
'sort'
: api_sort,
41
'order'
:
'desc'
,
42
}
43
)
44
params[
'url'
] = search_api + args
45
46
return
params
47
48
49
def
response
(resp):
50
51
results = []
52
json_data = loads(resp.text)
53
54
for
result
in
json_data[
'items'
]:
55
56
content =
"[%s]"
%
", "
.join(result[
'tags'
])
57
content +=
" %s"
% result[
'owner'
][
'display_name'
]
58
if
result[
'is_answered'
]:
59
content +=
' // is answered'
60
content +=
" // score: %s"
% result[
'score'
]
61
62
results.append(
63
{
64
'url'
:
"https://%s.com/q/%s"
% (api_site, result[
'question_id'
]),
65
'title'
: html.unescape(result[
'title'
]),
66
'content'
: html.unescape(content),
67
}
68
)
69
70
return
results
searx.engines.stackexchange.response
response(resp)
Definition
stackexchange.py:49
searx.engines.stackexchange.request
request(query, params)
Definition
stackexchange.py:32
searxng
searx
engines
stackexchange.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0