Created
May 4, 2011 19:59
-
-
Save hannahwhy/955910 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 tornado.ioloop | |
| import tornado.web | |
| import redis | |
| import urllib2 | |
| r = redis.Redis(host='127.0.0.1', port=6379, db=0) | |
| current_block="test" | |
| class MainHandler(tornado.web.RequestHandler): | |
| def get(self): | |
| self.write('I think you're in the wrong spot.') | |
| class GetNewID(tornado.web.RequestHandler): | |
| def get(self): | |
| uid=r.spop("gv_todo") | |
| self.write(uid) | |
| class AddID(tornado.web.RequestHandler): | |
| def get(self, vid_id): | |
| if not r.sismember("gv_todo", vid_id): | |
| if not r.sismember("gv_done", vid_id): | |
| if not r.sismember("gv_downloaded", vid_id): | |
| if not r.sismember("gv_processing", vid_id): | |
| r.sadd('gv_todo', vid_id) | |
| class FinishID(tornado.web.RequestHandler): | |
| def get(self, vid_id): | |
| if not r.sismember('gv_downloaded', vid_id): | |
| if not r.sismember('gv_processing', vid_id): | |
| r.sadd('gv_done', vid_id) | |
| if __name__ == "__main__": | |
| application = tornado.web.Application([ | |
| (r"/", MainHandler), | |
| (r"/getIDToCheck", GetNewID), | |
| (r"/addID/([0-9-]+)", AddID), | |
| (r"/finish/([0-9-]+)", FinishID), | |
| ]) | |
| application.listen(8080) | |
| tornado.ioloop.IOLoop.instance().start() |
This file contains hidden or 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 tornado.ioloop | |
| import tornado.web | |
| import redis | |
| import urllib2 | |
| r = redis.Redis(host='127.0.0.1', port=6379, db=0) | |
| current_block="test" | |
| class MainHandler(tornado.web.RequestHandler): | |
| def get(self): | |
| self.write('I think you're in the wrong spot.') | |
| class IntroduceClient(tornado.web.RequestHandler): | |
| def get(self, user_id, ip): | |
| r.setnx(user_id, ip) | |
| self.write("Success") | |
| class GetID(tornado.web.RequestHandler): | |
| def get(self, user): | |
| id=r.spop('gv_done') | |
| r.sadd('gv_processing', id) | |
| r.setex(id,user,10800) | |
| self.write(id) | |
| class FinishID(tornado.web.RequestHandler): | |
| def get(self, user_id, vid_id, size, hash): | |
| r.delete(vid_id) | |
| r.srem('gv_done',vid_id) | |
| r.srem('gv_processing',vid_id) | |
| r.sadd('gv_downloaded',vid_id) | |
| r.hmset(vid_id, dict({'user': user_id, 'size': size, 'hash': hash})) | |
| if __name__ == "__main__": | |
| application = tornado.web.Application([ | |
| (r"/", MainHandler), | |
| (r"/introduce/([a-zA-Z0-9-_]+)/([0-9.]+)", IntroduceClient), | |
| (r"/getID/([a-zA-Z0-9-_]+)", GetID), | |
| (r"/finishVid/([a-zA-Z0-9-_]+)/([0-9-]+)/([0-9]+)/([a-z0-9A-Z]+)", FinishID), | |
| ]) | |
| application.listen(8081) | |
| tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment