Commit a72745c1dc2cc03d2c66d6ec23238a0c86b0461d

  • avatar
  • arvind
  • Fri Aug 22 20:35:54 IST 2014
Add route to search dataset made available by OpenCultuurData APIs.
  • Diff rendering mode:
  • inline
  • side by side

swtr/server.py

1# -*- coding: utf8 -*-
1# -*- coding: utf-8 -*-
22
3import flask3import flask
4from flask import session4from flask import session
202 refresh_token=auth_tok['refresh_token'],202 refresh_token=auth_tok['refresh_token'],
203 config=config,203 config=config,
204 url=flask.request.args.get('where'))204 url=flask.request.args.get('where'))
205
206
207@app.route("/search")
208def search():
209 if 'size' not in flask.request.args:
210 size = 10
211 else:
212 size = flask.request.args['size']
213 if 'from' not in flask.request.args:
214 fr = 0
215 else:
216 fr = flask.request.args['from']
217
218 results = requests.post("http://api.opencultuurdata.nl/v0/search",
219 data=json.dumps({
220 "query": flask.request.args['term'],
221 "facets": {"collection": {},
222 "date": {"interval": "day"}},
223 "filters": {"media_content_type":
224 {"terms": ["image/jpeg",
225 "image/png"]}},
226 "size": size,
227 "from": fr}))
228 return flask.jsonify(results.json())
229
205230
206# if the app is run directly from command-line231# if the app is run directly from command-line
207# assume its being run locally in a dev environment232# assume its being run locally in a dev environment