diff --git a/flasky.py b/flasky.py index ea38421..242e69c 100644 --- a/flasky.py +++ b/flasky.py @@ -95,14 +95,26 @@ def movie_list(lang='en'): @app.route('/movie//', methods=['GET']) +@app.route('/movie///', methods=['GET']) @crossdomain(origin='*') -def movie_item(mid): +def movie_item(mid, lang='en'): + lang = lang if lang in ('en', 'th') else 'en' try: movie = db.movies.find_one({'tmdb_id': int(mid)}) except ValueError: movie = db.movies.find_one({'_id': bson.objectid.ObjectId(mid)}) if not movie: movie = {} + for k in ('title', 'tagline', 'director', 'cast', 'storyline'): + if movie[k][lang]: + movie[k] = movie[k][lang] + else: + movie[k] = movie[k]['th' if lang == 'en' else lang] + try: + del movie['indexes'] + except KeyError: + pass + r = make_response(dumps(movie, default=miscObjHandler)) r.mimetype = 'application/json' return r