Example #1
0
 def register_wspush(uid, redis):
     """Register account in WSpush. 
     """
     t = int(time.time()) * 1000
     key = get_push_key(uid, t)
     res = WSPushHelper.register(uid, t, key, redis)
     return res
Example #2
0
    def pushS3_dummy(uids, db, redis):
        """
        S3
        Wspush a dummy s3 packet to individuals.

        :arg uids: list. e.g.
            [
                'xxx',
                'yyy'
            ]
        :arg db: database instance
        :arg redis: redis instance
        """

        t = int(time.time()) * 1000

        packet = dict(packet_type="S3",
                      res=[])
        
        for item in uids:
            push_key = get_push_key(item, t)
            res = WSPushHelper.push(item, t, push_key, packet, redis)
Example #3
0
    def push_packet(tid, packet, db, redis, t_info=None):
        """Push packet to tid.

        :arg tid: string
        :arg db: database instance 
        :arg redis: redis instance
        :arg t_info: dict, e.g.

            {
               'tid':'',
               'umobile':'',
               'group_id':'',
               'cid':'',
               'oid':[]
            }
 
        """
        # NOTE: t_info has higher priority compared with tid
        if not t_info:  # tid is avaliable
            t_info = QueryHelper.get_terminal_basic_info(tid, db)

        uid = t_info.get('umobile', '')
        cid = t_info.get('cid', '')
        oid = t_info.get('oid', [])

        t = int(time.time()) * 1000

        lst = []

        if uid:
            lst.append(uid)
        if cid:
            lst.append(cid) 
        if oid:
            lst.extend(oid)   

        for item in set(lst):      
            push_key = get_push_key(item, t)
            res = WSPushHelper.push(item, t, push_key, packet, redis)