Ejemplo n.º 1
0
Archivo: main.py Proyecto: zz2/webchat
    def GET(self, channel_uuid):
        '''返回指定channel下有哪些session '''
        try:
            ucm_self = db_session_mem.query(Ucm_)\
                .filter(Ucm_.channel_uuid==channel_uuid)\
                .filter(Ucm_.session_id==session.session_id)\
                .one()
        except NoResultFound:
            pass
        else:
            db_api.ucm_update(ucm_self.id, {'atime':datetime.datetime.now()})

        ucms = db_api.ucm_get_with_channel(channel_uuid)
        d = {'ucms':[]}
        for ucm in ucms:
            now = datetime.datetime.now()
            print 'atime:', (now - ucm.atime).seconds
            if (now - ucm.atime).seconds >= conf.ucm_expire:
                db_session_mem.delete(ucm)
                db_session_mem.commit()
            else:
                d['ucms'].append({
                    'session_id':ucm.session_id,
                    'nickname':ucm.nickname,
                    })
        print d
        web.header("Content-Type", "application/json")
        return json.dumps(d)
Ejemplo n.º 2
0
Archivo: main.py Proyecto: zz2/webchat
 def POST(self):
     x = web.input()
     nickname = x['nickname']
     session.nickname = nickname
     ucms = db_api.ucm_get_with_session(session.session_id)
     for ucm in ucms:
         db_api.ucm_update(ucm.id, {'nickname':nickname})
     return 'SUCC'