From a72745c1dc2cc03d2c66d6ec23238a0c86b0461d Mon Sep 17 00:00:00 2001 From: Arvind Date: Fri, 22 Aug 2014 20:35:54 +0530 Subject: [PATCH] Add route to search dataset made available by OpenCultuurData APIs. --- swtr/server.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/swtr/server.py b/swtr/server.py index 5606097..76e6be9 100644 --- a/swtr/server.py +++ b/swtr/server.py @@ -1,4 +1,4 @@ -# -*- coding: utf8 -*- +# -*- coding: utf-8 -*- import flask from flask import session @@ -203,6 +203,31 @@ def annotate(): config=config, url=flask.request.args.get('where')) + +@app.route("/search") +def search(): + if 'size' not in flask.request.args: + size = 10 + else: + size = flask.request.args['size'] + if 'from' not in flask.request.args: + fr = 0 + else: + fr = flask.request.args['from'] + + results = requests.post("http://api.opencultuurdata.nl/v0/search", + data=json.dumps({ + "query": flask.request.args['term'], + "facets": {"collection": {}, + "date": {"interval": "day"}}, + "filters": {"media_content_type": + {"terms": ["image/jpeg", + "image/png"]}}, + "size": size, + "from": fr})) + return flask.jsonify(results.json()) + + # if the app is run directly from command-line # assume its being run locally in a dev environment if __name__ == '__main__': -- 1.7.10.4