on master help sign in
[enh] opensearch xml added
commit6bddaf57022dea1783cd08c4d18e6744d1048bea authorasciimoo <asciimoo@gmail.com> dateWed 16 Oct 2013, 00:01 (13 years ago) parenta346327
2 files changed+27−1
searx/templates/base.html+1 searx/webapp.py+26−1
searx/templates/base.html+1
@@ -5,6 +5,7 @@
55 <meta http-equiv="content-language" content="en" />
66 <meta name="description" content="" />
77 <meta name="keywords" content="" />
8+ <link title="searx" type="application/opensearchdescription+xml" rel="search" href="/opensearch.xml"/>
89 <title>searx {% block title %}{% endblock %}</title>
910 <link rel="stylesheet" href="/static/css/style.css" type="text/css" media="screen" charset="utf-8" />
1011 {% block styles %}
searx/webapp.py+26−1
@@ -22,7 +22,7 @@ if __name__ == "__main__":
2222 from os.path import realpath, dirname
2323 path.append(realpath(dirname(realpath(__file__))+'/../'))
2424
25−from flask import Flask, request, flash, render_template
25+from flask import Flask, request, flash, render_template, url_for, Response
2626import ConfigParser
2727from os import getenv
2828from searx.engines import search, engines
@@ -37,6 +37,18 @@ cfg.read('searx.conf')
3737app = Flask(__name__)
3838app.secret_key = cfg.get('app', 'secret_key')
3939
40+opensearch_xml = '''<?xml version="1.0" encoding="utf-8"?>
41+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
42+ <ShortName>searx</ShortName>
43+ <Description>Search searx</Description>
44+ <InputEncoding>UTF-8</InputEncoding>
45+ <LongName>searx meta search engine</LongName>
46+ <Url type="text/html" method="post" template="{host}">
47+ <Param name="q" value="{{searchTerms}}" />
48+ </Url>
49+</OpenSearchDescription>
50+'''
51+
4052def render(template_name, **kwargs):
4153 kwargs['engines'] = engines.keys()
4254 return render_template(template_name, **kwargs)
@@ -58,6 +70,19 @@ def index():
5870 return render('results.html', results=results, q=query.decode('utf-8'))
5971 return render('index.html')
6072
73+@app.route('/favicon.ico', methods=['GET'])
74+def fav():
75+ return ''
76+
77+@app.route('/opensearch.xml', methods=['GET'])
78+def opensearch():
79+ global opensearch_xml
80+ ret = opensearch_xml.format(host=url_for('index', _external=True))
81+ resp = Response(response=ret,
82+ status=200,
83+ mimetype="application/xml")
84+ return resp
85+
6186if __name__ == "__main__":
6287 from gevent import monkey
6388 monkey.patch_all()