2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-05-02 13:45:17 +00:00
|
|
|
"""
|
|
|
|
Digg (News, Social media)
|
|
|
|
"""
|
2020-11-22 10:37:12 +00:00
|
|
|
# pylint: disable=missing-function-docstring
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
from json import loads
|
2020-08-06 15:42:46 +00:00
|
|
|
from urllib.parse import urlencode
|
2019-10-16 13:11:27 +00:00
|
|
|
from datetime import datetime
|
2014-12-28 21:57:59 +00:00
|
|
|
|
2020-12-02 20:54:27 +00:00
|
|
|
from lxml import html
|
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://digg.com',
|
|
|
|
"wikidata_id": 'Q270478',
|
|
|
|
"official_api_documentation": None,
|
|
|
|
"use_official_api": False,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'HTML',
|
|
|
|
}
|
|
|
|
|
2014-12-28 21:57:59 +00:00
|
|
|
# engine dependent config
|
|
|
|
categories = ['news', 'social media']
|
|
|
|
paging = True
|
2020-12-02 20:54:27 +00:00
|
|
|
base_url = 'https://digg.com'
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
# search-url
|
2020-12-02 20:54:27 +00:00
|
|
|
search_url = base_url + (
|
|
|
|
'/api/search/'
|
|
|
|
'?{query}'
|
|
|
|
'&from={position}'
|
|
|
|
'&size=20'
|
|
|
|
'&format=html'
|
|
|
|
)
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
def request(query, params):
|
2019-10-16 13:11:27 +00:00
|
|
|
offset = (params['pageno'] - 1) * 20
|
2020-12-02 20:54:27 +00:00
|
|
|
params['url'] = search_url.format(
|
|
|
|
query = urlencode({'q': query}),
|
|
|
|
position = offset,
|
|
|
|
)
|
2014-12-28 21:57:59 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
|
|
|
# parse results
|
2020-12-02 20:54:27 +00:00
|
|
|
for result in loads(resp.text)['mapped']:
|
|
|
|
|
|
|
|
# strip html tags and superfluous quotation marks from content
|
|
|
|
content = html.document_fromstring(
|
|
|
|
result['excerpt']
|
|
|
|
).text_content()
|
2015-05-02 09:43:12 +00:00
|
|
|
|
2020-10-30 08:36:11 +00:00
|
|
|
# 'created': {'ISO': '2020-10-16T14:09:55Z', ...}
|
2020-12-02 20:54:27 +00:00
|
|
|
published = datetime.strptime(
|
|
|
|
result['created']['ISO'], '%Y-%m-%dT%H:%M:%SZ'
|
|
|
|
)
|
|
|
|
results.append({
|
|
|
|
'url': result['url'],
|
|
|
|
'title': result['title'],
|
|
|
|
'content' : content,
|
|
|
|
'template': 'videos.html',
|
|
|
|
'publishedDate': published,
|
|
|
|
'thumbnail': result['images']['thumbImage'],
|
|
|
|
})
|
2014-12-28 21:57:59 +00:00
|
|
|
|
|
|
|
return results
|