summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorKirill Isakov <ukwt@ya.ru>2016-03-27 03:50:44 +0600
committerKirill Isakov <ukwt@ya.ru>2016-03-27 03:50:44 +0600
commitc1d456b1366e339b09bd3744b45bf80da1e7d808 (patch)
treef6b8c53b415a48bf2e94cccc4cce8c78f59a4f48 /searx/engines
parent547b8a87653d87b8be85710275a66be1bec1e39c (diff)
downloadsearxng-c1d456b1366e339b09bd3744b45bf80da1e7d808.tar.gz
searxng-c1d456b1366e339b09bd3744b45bf80da1e7d808.zip
Add F-Droid search engine
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/fdroid.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/searx/engines/fdroid.py b/searx/engines/fdroid.py
new file mode 100644
index 000000000..0b16773e3
--- /dev/null
+++ b/searx/engines/fdroid.py
@@ -0,0 +1,53 @@
+"""
+ 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 cgi import escape
+from urllib import urlencode
+from searx.engines.xpath import extract_text
+from lxml import html
+
+# 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 = escape(content.replace(title, '', 1).strip())
+
+ results.append({'url': url,
+ 'title': title,
+ 'content': content,
+ 'img_src': img_src})
+
+ return results