summaryrefslogtreecommitdiff
path: root/searx/engines/frinkiac.py
blob: f43bb6e20c452ee46ef3436a7eb4b1dd8ddaea03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# SPDX-License-Identifier: AGPL-3.0-or-later
"""
 Frinkiac (Images)
"""

from json import loads
from urllib.parse import urlencode

# about
about = {
    "website": 'https://frinkiac.com',
    "wikidata_id": 'Q24882614',
    "official_api_documentation": {
        'url': None,
        'comment': 'see https://github.com/MitchellAW/CompuGlobal'
    },
    "use_official_api": False,
    "require_api_key": False,
    "results": 'JSON',
}

categories = ['images']

BASE = 'https://frinkiac.com/'
SEARCH_URL = '{base}api/search?{query}'
RESULT_URL = '{base}?{query}'
THUMB_URL = '{base}img/{episode}/{timestamp}/medium.jpg'
IMAGE_URL = '{base}img/{episode}/{timestamp}.jpg'


def request(query, params):
    params['url'] = SEARCH_URL.format(base=BASE, query=urlencode({'q': query}))
    return params


def response(resp):
    results = []
    response_data = loads(resp.text)
    for result in response_data:
        episode = result['Episode']
        timestamp = result['Timestamp']

        results.append({'template': 'images.html',
                        'url': RESULT_URL.format(base=BASE,
                                                 query=urlencode({'p': 'caption', 'e': episode, 't': timestamp})),
                        'title': episode,
                        'content': '',
                        'thumbnail_src': THUMB_URL.format(base=BASE, episode=episode, timestamp=timestamp),
                        'img_src': IMAGE_URL.format(base=BASE, episode=episode, timestamp=timestamp)})

    return results