summaryrefslogtreecommitdiff
path: root/searx/engines/fdroid.py
blob: a6b01a8ee48fa4167b2a69e33c481f509b1a5a66 (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
"""
 F-Droid (a repository of FOSS applications for Android)

 @website      https://f-droid.org/
 @provide-api  no
 @using-api    no
 @results      HTML
 @stable       no (HTML can change)
 @parse        url, title, content
"""

from lxml import html
from searx.engines.xpath import extract_text
from searx.url_utils import urlencode

# engine dependent config
categories = ['files']
paging = True

# search-url
base_url = 'https://f-droid.org/'
search_url = base_url + 'repository/browse/?{query}'


# do search-request
def request(query, params):
    query = urlencode({'fdfilter': query, 'fdpage': params['pageno']})
    params['url'] = search_url.format(query=query)
    return params


# get response from search-request
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    for app in dom.xpath('//div[@id="appheader"]'):
        url = app.xpath('./ancestor::a/@href')[0]
        title = app.xpath('./p/span/text()')[0]
        img_src = app.xpath('.//img/@src')[0]

        content = extract_text(app.xpath('./p')[0])
        content = content.replace(title, '', 1).strip()

        results.append({'url': url,
                        'title': title,
                        'content': content,
                        'img_src': img_src})

    return results