From 13f41070a80575657d6503e6e913aba00ff64460 Mon Sep 17 00:00:00 2001 From: sipp11 Date: Tue, 28 Oct 2014 02:06:48 +0700 Subject: [PATCH] Adding movie(s) to API --- flasky.py | 35 +++++++++++++++++++++++++++++++++-- settings.py | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/flasky.py b/flasky.py index 5965fcc..024ee37 100644 --- a/flasky.py +++ b/flasky.py @@ -52,7 +52,7 @@ def crossdomain(origin=None, methods=None, headers=None, app = Flask(__name__) -client = MongoClient(**{'host': 'localhost', 'port': 27017}) +client = MongoClient(**{'host': '10.10.10.51', 'port': 27017}) db = client.showtimes miscObjHandler = lambda obj: ( @@ -67,6 +67,37 @@ def hello_world(): return 'This comes from Flask ^_^' +@app.route('/movies/', methods=['GET']) +@crossdomain(origin='*') +def movie_list(): + result = db.movies.find() + movies = [] + for i in result: + movies.append(i) + if len(movies) > 10: + break + json_dict = { + 'meta': { + 'total_count': len(movies) + }, + 'objects': movies + } + r = make_response(dumps(json_dict, default=miscObjHandler)) + r.mimetype = 'application/json' + return r + + +@app.route('/movie//', methods=['GET']) +@crossdomain(origin='*') +def movie_item(mid): + movie = db.movies.find_one({'id': int(mid)}) + if not movie: + movie = {} + r = make_response(dumps(movie, default=miscObjHandler)) + r.mimetype = 'application/json' + return r + + @app.route('/groups/', methods=['GET']) @crossdomain(origin='*') def groups(): @@ -77,7 +108,7 @@ def groups(): }, 'objects': known_groups } - r = make_response(dumps(json_dict)) + r = make_response(dumps(json_dict, default=miscObjHandler)) r.mimetype = 'application/json' return r diff --git a/settings.py b/settings.py index c78f46e..29c9f38 100644 --- a/settings.py +++ b/settings.py @@ -45,7 +45,7 @@ settings['xsrf_cookies'] = True settings['template_loader'] = tornado.template.Loader(TEMPLATE_ROOT) -SYSLOG_TAG = "stockintel" +SYSLOG_TAG = 'showtimes-serv' SYSLOG_FACILITY = logging.handlers.SysLogHandler.LOG_LOCAL2 # See PEP 391 and logconfig for formatting help. Each section of LOGGERS