on master help sign in
[fix] update digg engine
1057e42Adam Tauber
searx/engines/digg.py+12−24
@@ -15,7 +15,8 @@ import string
15from dateutil import parser
15from dateutil import parser
16from json import loads
16from json import loads
17from lxml import html
17from lxml import html
18−from searx.url_utils import quote_plus
18+from searx.url_utils import urlencode
19+from datetime import datetime
19
20
20# engine dependent config
21# engine dependent config
21categories = ['news', 'social media']
22categories = ['news', 'social media']
@@ -23,7 +24,7 @@ paging = True
23
24
24# search-url
25# search-url
25base_url = 'https://digg.com/'
26base_url = 'https://digg.com/'
26−search_url = base_url + 'api/search/{query}.json?position={position}&format=html'
27+search_url = base_url + 'api/search/?{query}&from={position}&size=20&format=html'
27
28
28# specific xpath variables
29# specific xpath variables
29results_xpath = '//article'
30results_xpath = '//article'
@@ -38,9 +39,9 @@ digg_cookie_chars = string.ascii_uppercase + string.ascii_lowercase +\
38
39
39# do search-request
40# do search-request
40def request(query, params):
41def request(query, params):
41− offset = (params['pageno'] - 1) * 10
42+ offset = (params['pageno'] - 1) * 20
42 params['url'] = search_url.format(position=offset,
43 params['url'] = search_url.format(position=offset,
43− query=quote_plus(query))
44+ query=urlencode({'q': query}))
44 params['cookies']['frontend.auid'] = ''.join(random.choice(
45 params['cookies']['frontend.auid'] = ''.join(random.choice(
45 digg_cookie_chars) for _ in range(22))
46 digg_cookie_chars) for _ in range(22))
46 return params
47 return params
@@ -52,30 +53,17 @@ def response(resp):
52
53
53 search_result = loads(resp.text)
54 search_result = loads(resp.text)
54
55
55− if 'html' not in search_result or search_result['html'] == '':
56− return results
57−
58− dom = html.fromstring(search_result['html'])
59−
60 # parse results
56 # parse results
61− for result in dom.xpath(results_xpath):
57+ for result in search_result['mapped']:
62− url = result.attrib.get('data-contenturl')
63− thumbnail = result.xpath('.//img')[0].attrib.get('src')
64− title = ''.join(result.xpath(title_xpath))
65− content = ''.join(result.xpath(content_xpath))
66− pubdate = result.xpath(pubdate_xpath)[0].attrib.get('datetime')
67− publishedDate = parser.parse(pubdate)
68−
69− # http to https
70− thumbnail = thumbnail.replace("http://static.digg.com", "https://static.digg.com")
71
58
59+ published = datetime.strptime(result['created']['ISO'], "%Y-%m-%d %H:%M:%S")
72 # append result
60 # append result
73− results.append({'url': url,
61+ results.append({'url': result['url'],
74− 'title': title,
62+ 'title': result['title'],
75− 'content': content,
63+ 'content': result['excerpt'],
76 'template': 'videos.html',
64 'template': 'videos.html',
77− 'publishedDate': publishedDate,
65+ 'publishedDate': published,
78− 'thumbnail': thumbnail})
66+ 'thumbnail': result['images']['thumbImage']})
79
67
80 # return results
68 # return results
81 return results
69 return results