From 3d8b7ea3ea100a72a0a18c9161cf688d6586f8f0 Mon Sep 17 00:00:00 2001 From: asciimoo Date: Thu, 17 Oct 2013 00:30:41 +0200 Subject: [PATCH] [enh] json output support --- searx/webapp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/searx/webapp.py b/searx/webapp.py index afd7d19ca..02fb92058 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -26,6 +26,7 @@ from flask import Flask, request, flash, render_template, url_for, Response import ConfigParser from os import getenv from searx.engines import search, engines +import json cfg = ConfigParser.SafeConfigParser() cfg.read('/etc/searx.conf') @@ -67,6 +68,9 @@ def index(): selected_engines = engines.keys() query = request.form['q'].encode('utf-8') 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('index.html')