Created
April 22, 2013 12:39
-
-
Save jasonbartz/5434605 to your computer and use it in GitHub Desktop.
For posting lots of things really fast.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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