Commit a72745c1dc2cc03d2c66d6ec23238a0c86b0461d
- Diff rendering mode:
- inline
- side by side
swtr/server.py
(26 / 1)
  | |||
1 | # -*- coding: utf8 -*- | ||
1 | # -*- coding: utf-8 -*- | ||
2 | 2 | ||
3 | 3 | import flask | |
4 | 4 | from flask import session | |
… | … | ||
202 | 202 | refresh_token=auth_tok['refresh_token'], | |
203 | 203 | config=config, | |
204 | 204 | url=flask.request.args.get('where')) | |
205 | |||
206 | |||
207 | @app.route("/search") | ||
208 | def 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 | |||
205 | 230 | ||
206 | 231 | # if the app is run directly from command-line | |
207 | 232 | # assume its being run locally in a dev environment |