@@ -15,7 +15,8 @@ import string
1515from dateutil import parser
1616from json import loads
1717from lxml import html
18−from searx.url_utils import quote_plus
18+from searx.url_utils import urlencode
19+from datetime import datetime
1920
2021# engine dependent config
2122categories = ['news', 'social media']
@@ -23,7 +24,7 @@ paging = True
2324
2425# search-url
2526base_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'
2728
2829# specific xpath variables
2930results_xpath = '//article'
@@ -38,9 +39,9 @@ digg_cookie_chars = string.ascii_uppercase + string.ascii_lowercase +\
3839
3940# do search-request
4041def request(query, params):
41− offset = (params['pageno'] - 1) * 10
42+ offset = (params['pageno'] - 1) * 20
4243 params['url'] = search_url.format(position=offset,
43− query=quote_plus(query))
44+ query=urlencode({'q': query}))
4445 params['cookies']['frontend.auid'] = ''.join(random.choice(
4546 digg_cookie_chars) for _ in range(22))
4647 return params
@@ -52,30 +53,17 @@ def response(resp):
5253
5354 search_result = loads(resp.text)
5455
55− if 'html' not in search_result or search_result['html'] == '':
56− return results
57−
58− dom = html.fromstring(search_result['html'])
59−
6056 # parse results
61− for result in dom.xpath(results_xpath):
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")
57+ for result in search_result['mapped']:
7158
59+ published = datetime.strptime(result['created']['ISO'], "%Y-%m-%d %H:%M:%S")
7260 # append result
73− results.append({'url': url,
74− 'title': title,
75− 'content': content,
61+ results.append({'url': result['url'],
62+ 'title': result['title'],
63+ 'content': result['excerpt'],
7664 'template': 'videos.html',
77− 'publishedDate': publishedDate,
78− 'thumbnail': thumbnail})
65+ 'publishedDate': published,
66+ 'thumbnail': result['images']['thumbImage']})
7967
8068 # return results
8169 return results