summaryrefslogtreecommitdiff
path: root/searx/engines/emojipedia.py
blob: 020bf689b687f345af7afb24bfb2bc6343c1ebe7 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-License-Identifier: AGPL-3.0-or-later
# lint: pylint
"""Emojipedia

Emojipedia is an emoji reference website which documents the meaning and
common usage of emoji characters in the Unicode Standard.  It is owned by Zedge
since 2021. Emojipedia is a voting member of The Unicode Consortium.[1]

[1] https://en.wikipedia.org/wiki/Emojipedia
"""

from urllib.parse import urlencode
from lxml import html

from searx.utils import (
    eval_xpath_list,
    eval_xpath_getindex,
    extract_text,
)

about = {
    "website": 'https://emojipedia.org',
    "wikidata_id": 'Q22908129',
    "official_api_documentation": None,
    "use_official_api": False,
    "require_api_key": False,
    "results": 'HTML',
}

categories = []
paging = False
time_range_support = False

base_url = 'https://emojipedia.org'
search_url = base_url + '/search/?{query}'


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


def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    for result in eval_xpath_list(dom, "//ol[@class='search-results']/li"):

        extracted_desc = extract_text(eval_xpath_getindex(result, './/p', 0))

        if 'No results found.' in extracted_desc:
            break

        link = eval_xpath_getindex(result, './/h2/a', 0)

        url = base_url + link.attrib.get('href')
        title = extract_text(link)
        content = extracted_desc

        res = {'url': url, 'title': title, 'content': content}

        results.append(res)

    return results