| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 | # SPDX-License-Identifier: AGPL-3.0-or-later""" Digg (News, Social media)"""# pylint: disable=missing-function-docstringfrom json import loadsfrom urllib.parse import urlencodefrom datetime import datetimefrom lxml import html# aboutabout = {    "website": 'https://digg.com',    "wikidata_id": 'Q270478',    "official_api_documentation": None,    "use_official_api": False,    "require_api_key": False,    "results": 'HTML',}# engine dependent configcategories = ['news', 'social media']paging = Truebase_url = 'https://digg.com'# search-urlsearch_url = base_url + (    '/api/search/'    '?{query}'    '&from={position}'    '&size=20'    '&format=html')def request(query, params):    offset = (params['pageno'] - 1) * 20    params['url'] = search_url.format(        query = urlencode({'q': query}),        position = offset,    )    return paramsdef response(resp):    results = []    # parse results    for result in loads(resp.text)['mapped']:        # strip html tags and superfluous quotation marks from content        content = html.document_fromstring(            result['excerpt']        ).text_content()        # 'created': {'ISO': '2020-10-16T14:09:55Z', ...}        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'],        })    return results
 |