2015-05-02 13:45:17 +00:00
|
|
|
"""
|
|
|
|
Digg (News, Social media)
|
|
|
|
|
|
|
|
@website https://digg.com/
|
|
|
|
@provide-api no
|
|
|
|
|
|
|
|
@using-api no
|
|
|
|
@results HTML (using search portal)
|
|
|
|
@stable no (HTML can change)
|
|
|
|
@parse url, title, content, publishedDate, thumbnail
|
|
|
|
"""
|
2014-12-28 21:57:59 +00:00
|
|
|
|
2017-08-30 16:20:43 +00:00
|
|
|
import random
|
|
|
|
import string
|
2016-11-30 17:43:03 +00:00
|
|
|
from dateutil import parser
|
2014-12-28 21:57:59 +00:00
|
|
|
from json import loads
|
|
|
|
from lxml import html
|
2019-10-16 13:11:27 +00:00
|
|
|
from searx.url_utils import urlencode
|
|
|
|
from datetime import datetime
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
# engine dependent config
|
|
|
|
categories = ['news', 'social media']
|
|
|
|
paging = True
|
|
|
|
|
|
|
|
# search-url
|
|
|
|
base_url = 'https://digg.com/'
|
2019-10-16 13:11:27 +00:00
|
|
|
search_url = base_url + 'api/search/?{query}&from={position}&size=20&format=html'
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
# specific xpath variables
|
|
|
|
results_xpath = '//article'
|
|
|
|
link_xpath = './/small[@class="time"]//a'
|
|
|
|
title_xpath = './/h2//a//text()'
|
|
|
|
content_xpath = './/p//text()'
|
|
|
|
pubdate_xpath = './/time'
|
|
|
|
|
2017-08-30 19:14:12 +00:00
|
|
|
digg_cookie_chars = string.ascii_uppercase + string.ascii_lowercase +\
|
|
|
|
string.digits + "+_"
|
|
|
|
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
# do search-request
|
|
|
|
def request(query, params):
|
2019-10-16 13:11:27 +00:00
|
|
|
offset = (params['pageno'] - 1) * 20
|
2014-12-28 21:57:59 +00:00
|
|
|
params['url'] = search_url.format(position=offset,
|
2019-10-16 13:11:27 +00:00
|
|
|
query=urlencode({'q': query}))
|
2017-08-30 16:20:43 +00:00
|
|
|
params['cookies']['frontend.auid'] = ''.join(random.choice(
|
2017-08-30 19:14:12 +00:00
|
|
|
digg_cookie_chars) for _ in range(22))
|
2014-12-28 21:57:59 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
|
|
|
search_result = loads(resp.text)
|
|
|
|
|
|
|
|
# parse results
|
2019-10-16 13:11:27 +00:00
|
|
|
for result in search_result['mapped']:
|
2015-05-02 09:43:12 +00:00
|
|
|
|
2019-10-16 13:11:27 +00:00
|
|
|
published = datetime.strptime(result['created']['ISO'], "%Y-%m-%d %H:%M:%S")
|
2014-12-28 21:57:59 +00:00
|
|
|
# append result
|
2019-10-16 13:11:27 +00:00
|
|
|
results.append({'url': result['url'],
|
|
|
|
'title': result['title'],
|
|
|
|
'content': result['excerpt'],
|
2014-12-28 21:57:59 +00:00
|
|
|
'template': 'videos.html',
|
2019-10-16 13:11:27 +00:00
|
|
|
'publishedDate': published,
|
|
|
|
'thumbnail': result['images']['thumbImage']})
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
# return results
|
|
|
|
return results
|