summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
Diffstat (limited to 'searx')
-rw-r--r--searx/engines/piratebay.py2
-rw-r--r--searx/templates/categories.html5
-rw-r--r--searx/templates/index.html1
-rw-r--r--searx/templates/preferences.html19
-rw-r--r--searx/templates/results.html1
-rw-r--r--searx/templates/search.html6
-rw-r--r--searx/webapp.py45
7 files changed, 62 insertions, 17 deletions
diff --git a/searx/engines/piratebay.py b/searx/engines/piratebay.py
index a7e1becc4..95ab884d5 100644
--- a/searx/engines/piratebay.py
+++ b/searx/engines/piratebay.py
@@ -5,7 +5,7 @@ from urllib import quote
categories = ['videos', 'music']
-url = 'https://thepiratebay.sx/'
+url = 'https://thepiratebay.se/'
search_url = url + 'search/{search_term}/0/99/{search_type}'
search_types = {'videos': '200'
,'music' : '100'
diff --git a/searx/templates/categories.html b/searx/templates/categories.html
new file mode 100644
index 000000000..4c693f3dd
--- /dev/null
+++ b/searx/templates/categories.html
@@ -0,0 +1,5 @@
+{% for category in categories %}
+ <div class="checkbox_container">
+ <input type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} /><label for="checkbox_{{ category|replace(' ', '_') }}" class="cb"></label><label for="checkbox_{{ category|replace(' ', '_') }}">{{ category }}</label>
+ </div>
+{% endfor %}
diff --git a/searx/templates/index.html b/searx/templates/index.html
index 4d13b77e7..bdb31e844 100644
--- a/searx/templates/index.html
+++ b/searx/templates/index.html
@@ -6,6 +6,7 @@
{% include 'search.html' %}
<p class="top_margin">
<a href="/about" class="hmarg">about</a>
+ <a href="/preferences" class="hmarg">preferences</a>
</p>
</div>
{% endblock %}
diff --git a/searx/templates/preferences.html b/searx/templates/preferences.html
new file mode 100644
index 000000000..705139e58
--- /dev/null
+++ b/searx/templates/preferences.html
@@ -0,0 +1,19 @@
+{% extends "base.html" %}
+{% block head %} {% endblock %}
+{% block content %}
+<div class="row">
+ <h2>Preferences</h2>
+
+
+ <fieldset>
+ <legend>Default categories</legend>
+ <form method="post" action="/preferences" id="search_form">
+ <p>
+ {% include 'categories.html' %}
+ </p>
+ <input type="submit" value="save" />
+ </form>
+ </fieldset>
+ <div class="right"><a href="/">back</a></div>
+</div>
+{% endblock %}
diff --git a/searx/templates/results.html b/searx/templates/results.html
index 2f018881c..c20f2d862 100644
--- a/searx/templates/results.html
+++ b/searx/templates/results.html
@@ -1,6 +1,7 @@
{% extends "base.html" %}
{% block title %}{{ q }} - {% endblock %}
{% block content %}
+<div class="right"><a href="/preferences">preferences</a></div>
<div class="small">
{% include 'search.html' %}
</div>
diff --git a/searx/templates/search.html b/searx/templates/search.html
index 07df31ef5..12d507335 100644
--- a/searx/templates/search.html
+++ b/searx/templates/search.html
@@ -4,10 +4,6 @@
<input type="submit" value="" id="search_submit" />
</div>
<div>
- {% for category in categories %}
- <div class="checkbox_container">
- <input type="checkbox" id="checkbox_{{ category|replace(' ', '_') }}" name="category_{{ category }}" {% if category in selected_categories %}checked="checked"{% endif %} /><label for="checkbox_{{ category|replace(' ', '_') }}" class="cb"></label><label for="checkbox_{{ category|replace(' ', '_') }}">{{ category }}</label>
- </div>
- {% endfor %}
+ {% include 'categories.html' %}
</div>
</form>
diff --git a/searx/webapp.py b/searx/webapp.py
index 20534416f..b7e2a4674 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -22,7 +22,7 @@ if __name__ == "__main__":
from sys import path
path.append(os.path.realpath(os.path.dirname(os.path.realpath(__file__))+'/../'))
-from flask import Flask, request, render_template, url_for, Response, make_response
+from flask import Flask, request, render_template, url_for, Response, make_response, redirect
from searx.engines import search, categories, engines, get_engines_stats
from searx import settings
import json
@@ -91,6 +91,11 @@ def index():
continue
selected_categories.append(category)
if not len(selected_categories):
+ cookie_categories = request.cookies.get('categories', '').split(',')
+ for ccateg in cookie_categories:
+ if ccateg in categories:
+ selected_categories.append(ccateg)
+ if not len(selected_categories):
selected_categories = ['general']
for categ in selected_categories:
@@ -119,29 +124,46 @@ def index():
response.headers.add('Content-Disposition', 'attachment;Filename=searx_-_{0}.csv'.format('_'.join(query.split())))
return response
- template = render('results.html'
- ,results=results
- ,q=request_data['q']
- ,selected_categories=selected_categories
- ,number_of_results=len(results)
- ,suggestions=suggestions
- )
- resp = make_response(template)
- resp.set_cookie('categories', ','.join(selected_categories))
+ return render('results.html'
+ ,results=results
+ ,q=request_data['q']
+ ,selected_categories=selected_categories
+ ,number_of_results=len(results)
+ ,suggestions=suggestions
+ )
- return resp
@app.route('/about', methods=['GET'])
def about():
global categories
return render('about.html', categs=categories.items())
+
+@app.route('/preferences', methods=['GET', 'POST'])
+def preferences():
+
+ if request.method=='POST':
+ selected_categories = []
+ for pd_name,pd in request.form.items():
+ if pd_name.startswith('category_'):
+ category = pd_name[9:]
+ if not category in categories:
+ continue
+ selected_categories.append(category)
+ if selected_categories:
+ resp = make_response(redirect('/'))
+ resp.set_cookie('categories', ','.join(selected_categories))
+ return resp
+ return render('preferences.html')
+
+
@app.route('/stats', methods=['GET'])
def stats():
global categories
stats = get_engines_stats()
return render('stats.html', stats=stats)
+
@app.route('/robots.txt', methods=['GET'])
def robots():
return Response("""User-agent: *
@@ -150,6 +172,7 @@ Allow: /about
Disallow: /stats
""", mimetype='text/plain')
+
@app.route('/opensearch.xml', methods=['GET'])
def opensearch():
global opensearch_xml