Esempio n. 1
0
 def __init__(self):
     handlers = [
         (r"/", MainHandler),
         (r"/auth/login", WeiboAuthHandler),
         (r"/auth/logout", LogoutHandler),
         (r"/vote", VoteHandler),
     ]
     settings = dict(
         static_path=os.path.join(os.path.dirname(__file__), "public"),
         cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
         login_url="/auth/login",
         debug=True,
         xsrf_cookies=True,
         weibo_consumer_key='100689067',
         weibo_consumer_secret='1f54eff4858b924d090833d537335bd8',
         flash_policy_port = 843,
         flash_policy_file = op.join(ROOT, 'flashpolicy.xml'),
         socket_io_port = 8000,
     )
     VoteRouter = TornadioRouter(VoteConnection,
                         dict(enabled_protocols=['websocket', 'xhr-polling',
                                                 'jsonp-polling', 'htmlfile']))
     tornado.web.Application.__init__(self, VoteRouter.apply_routes(handlers), **settings)
     #self.redis = redis.StrictRedis()
     self.adb = opermongo.asyncdb(database='test')
     self.db = opermongo.db(database='test')
Esempio n. 2
0
    def vote(self, c):
        self.db = opermongo.db(database='test')
        # 获取vote集合里面的赞成和反对票数实时展现到前端
        data = self.db.vote.find_one({},{'_id':0}) 

        return [data.get('approve', 0), data.get('refuse', 0)]