Skip to content

Instantly share code, notes, and snippets.

@jasonbartz
Created April 22, 2013 12:39
Show Gist options
  • Save jasonbartz/5434605 to your computer and use it in GitHub Desktop.
Save jasonbartz/5434605 to your computer and use it in GitHub Desktop.
For posting lots of things really fast.
import datetime
import tornado.ioloop
import tornado.web
import motor
from tornado import gen
db = motor.MotorClient().open_sync().test
class HomeHandler(tornado.web.RequestHandler):
@tornado.web.asynchronous
@gen.engine
def get(self):
cursor = db.bright.find().sort([('_id', -1)])
output = {
'messages': []
}
while (yield cursor.fetch_next):
output['messages'].append(cursor.next_object()["my user id"])
self.write(output)
self.finish()
class MainHandler(tornado.web.RequestHandler):
def get(self):
db.bright.insert({'my user id': datetime.datetime.now().strftime('%s.%f')})
self.write('')
application = tornado.web.Application([
(r"/post-data", MainHandler),
(r"/", HomeHandler),
], debug=True)
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment