mirror of
https://github.com/searxng/searxng.git
synced 2024-11-17 18:00:12 +01:00
[enh] json output support
This commit is contained in:
parent
e467a24843
commit
3d8b7ea3ea
@ -26,6 +26,7 @@ from flask import Flask, request, flash, render_template, url_for, Response
|
|||||||
import ConfigParser
|
import ConfigParser
|
||||||
from os import getenv
|
from os import getenv
|
||||||
from searx.engines import search, engines
|
from searx.engines import search, engines
|
||||||
|
import json
|
||||||
|
|
||||||
cfg = ConfigParser.SafeConfigParser()
|
cfg = ConfigParser.SafeConfigParser()
|
||||||
cfg.read('/etc/searx.conf')
|
cfg.read('/etc/searx.conf')
|
||||||
@ -67,6 +68,9 @@ def index():
|
|||||||
selected_engines = engines.keys()
|
selected_engines = engines.keys()
|
||||||
query = request.form['q'].encode('utf-8')
|
query = request.form['q'].encode('utf-8')
|
||||||
results = search(query, request, selected_engines)
|
results = search(query, request, selected_engines)
|
||||||
|
if request.form.get('format') == 'json':
|
||||||
|
# TODO HTTP headers
|
||||||
|
return json.dumps({'query': query, 'results': results})
|
||||||
return render('results.html', results=results, q=query.decode('utf-8'))
|
return render('results.html', results=results, q=query.decode('utf-8'))
|
||||||
return render('index.html')
|
return render('index.html')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user