From 2b48ab873e62b332cdd1ea6e025db332e1e543e5 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Fri, 2 Aug 2019 19:57:58 +0000 Subject: [PATCH] Add nibl search engine --- Dockerfile | 3 +++ engines/nibl.py | 28 ++++++++++++++++++++++++++++ result_templates/file.html | 15 +++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 engines/nibl.py create mode 100644 result_templates/file.html diff --git a/Dockerfile b/Dockerfile index 14ffdda..288f269 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,4 +22,7 @@ WORKDIR /searx RUN sed -i -e 's/default_on = False/default_on = True/' searx/plugins/oa_doi_rewrite.py \ && sed -i -e 's/oadoi.org/sci-hub.tw/' searx/preferences.py +COPY engines/* searx/engines/ +COPY result_templates/* searx/templates/oscar/result_templates/ + ENTRYPOINT ["tini", "--", "gunicorn", "searx.webapp", "--bind", "[::]:8000", "-w", "4"] diff --git a/engines/nibl.py b/engines/nibl.py new file mode 100644 index 0000000..953fcb8 --- /dev/null +++ b/engines/nibl.py @@ -0,0 +1,28 @@ +from lxml import html +from searx.engines.xpath import extract_text +from searx.url_utils import quote + +url = 'https://nibl.co.uk/bots.php' +search_url = url + '?search={query}' + +def request(query, params): + params['url'] = search_url.format(query=quote(query)) + + return params + +def response(resp): + results = [] + + dom = html.fromstring(resp.text.encode('utf-8')) + + for result in dom.xpath('//tr[starts-with(@class, "botlistitem")]'): + filename = extract_text(result.xpath('td[@class="filename"]/text()')) + href = url + result.xpath('td[@class="filename"]/a/@href')[0] + filesize = result.xpath('td[@class="filesize"]/text()')[0] + + results.append({'url': href, + 'title': filename, + 'filesize': filesize, + 'template': 'file.html'}) + + return results diff --git a/result_templates/file.html b/result_templates/file.html new file mode 100644 index 0000000..b9ac2c7 --- /dev/null +++ b/result_templates/file.html @@ -0,0 +1,15 @@ +{% from 'oscar/macros.html' import result_header, result_sub_header, result_footer, result_footer_rtl, icon %} + +{{ result_header(result, favicons) }} +{{ result_sub_header(result) }} + +{% if result.filesize %}
{{ icon('floppy-disk') }} {{ _('Filesize') }} + + {{ result.filesize }} +{% endif %} + +{% if rtl %} +{{ result_footer_rtl(result) }} +{% else %} +{{ result_footer(result) }} +{% endif %}