.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.reddit Namespace Reference

Functions

 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['social media']
 
int page_size = 25
 
str base_url = 'https://www.reddit.com/'
 
str search_url = base_url + 'search.json?{query}'
 

Detailed Description

Reddit

Function Documentation

◆ request()

searx.engines.reddit.request ( query,
params )

Definition at line 29 of file reddit.py.

29def request(query, params):
30
31 query = urlencode({'q': query, 'limit': page_size})
32 params['url'] = search_url.format(query=query)
33
34 return params
35
36

◆ response()

searx.engines.reddit.response ( resp)

Definition at line 37 of file reddit.py.

37def response(resp):
38
39 img_results = []
40 text_results = []
41
42 search_results = json.loads(resp.text)
43
44 # return empty array if there are no results
45 if 'data' not in search_results:
46 return []
47
48 posts = search_results.get('data', {}).get('children', [])
49
50 # process results
51 for post in posts:
52 data = post['data']
53
54 # extract post information
55 params = {'url': urljoin(base_url, data['permalink']), 'title': data['title']}
56
57 # if thumbnail field contains a valid URL, we need to change template
58 thumbnail = data['thumbnail']
59 url_info = urlparse(thumbnail)
60 # netloc & path
61 if url_info[1] != '' and url_info[2] != '':
62 params['img_src'] = data['url']
63 params['thumbnail_src'] = thumbnail
64 params['template'] = 'images.html'
65 img_results.append(params)
66 else:
67 created = datetime.fromtimestamp(data['created_utc'])
68 content = data['selftext']
69 if len(content) > 500:
70 content = content[:500] + '...'
71 params['content'] = content
72 params['publishedDate'] = created
73 text_results.append(params)
74
75 # show images first and text results second
76 return img_results + text_results

Variable Documentation

◆ about

dict searx.engines.reddit.about
Initial value:
1= {
2 "website": 'https://www.reddit.com/',
3 "wikidata_id": 'Q1136',
4 "official_api_documentation": 'https://www.reddit.com/dev/api',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 11 of file reddit.py.

◆ base_url

str searx.engines.reddit.base_url = 'https://www.reddit.com/'

Definition at line 25 of file reddit.py.

◆ categories

list searx.engines.reddit.categories = ['social media']

Definition at line 21 of file reddit.py.

◆ page_size

int searx.engines.reddit.page_size = 25

Definition at line 22 of file reddit.py.

◆ search_url

str searx.engines.reddit.search_url = base_url + 'search.json?{query}'

Definition at line 26 of file reddit.py.