Browse Source

Adding movie(s) to API

master
sipp11 10 years ago
parent
commit
13f41070a8
  1. 35
      flasky.py
  2. 2
      settings.py

35
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/<mid>/', 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

2
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

Loading…
Cancel
Save