Skip to content

Instantly share code, notes, and snippets.

@ntrepid8
Created February 1, 2014 15:34
Show Gist options
  • Save ntrepid8/8753805 to your computer and use it in GitHub Desktop.
Save ntrepid8/8753805 to your computer and use it in GitHub Desktop.
class MessagesHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@tornado.gen.engine
def get(self):
db = self.settings['db']
rb = []
cursor = db.messages.find().sort([('_id', -1)])
messages = yield motor.Op(cursor.to_list, length=50)
while messages:
[rb.append({'id': m['_id'], 'msg': m['msg']}) for m in messages]
messages = yield motor.Op(cursor.to_list, length=50)
self.finish({"data": rb})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment