on master help sign in
[fix] incorrect URLs in Reddit results - closes #538
4eeb5fbKirill Isakov
searx/engines/reddit.py+5−3
@@ -13,7 +13,7 @@
13import json
13import json
14from cgi import escape
14from cgi import escape
15from urllib import urlencode
15from urllib import urlencode
16−from urlparse import urlparse
16+from urlparse import urlparse, urljoin
17from datetime import datetime
17from datetime import datetime
18
18
19# engine dependent config
19# engine dependent config
@@ -21,7 +21,8 @@ categories = ['general', 'images', 'news', 'social media']
21page_size = 25
21page_size = 25
22
22
23# search-url
23# search-url
24−search_url = 'https://www.reddit.com/search.json?{query}'
24+base_url = 'https://www.reddit.com/'
25+search_url = base_url + 'search.json?{query}'
25
26
26
27
27# do search-request
28# do search-request
@@ -52,7 +53,7 @@ def response(resp):
52
53
53 # extract post information
54 # extract post information
54 params = {
55 params = {
55− 'url': data['url'],
56+ 'url': urljoin(base_url, data['permalink']),
56 'title': data['title']
57 'title': data['title']
57 }
58 }
58
59
@@ -61,6 +62,7 @@ def response(resp):
61 url_info = urlparse(thumbnail)
62 url_info = urlparse(thumbnail)
62 # netloc & path
63 # netloc & path
63 if url_info[1] != '' and url_info[2] != '':
64 if url_info[1] != '' and url_info[2] != '':
65+ params['img_src'] = data['url']
64 params['thumbnail_src'] = thumbnail
66 params['thumbnail_src'] = thumbnail
65 params['template'] = 'images.html'
67 params['template'] = 'images.html'
66 img_results.append(params)
68 img_results.append(params)