Exemple #1
0
    def get_batches(self):
        #用于存储需要更新的内容,可能涉及多个表、多个列族
        batches = []

        #根据关系用户,将关系用户的Profile插入到表中
        for uid, user in self.users.iteritems():
            uprofile = UserProfile()
            uprofile.load(user)
            batches_uprofile = uprofile.get_batches()
            batches.extend(batches_uprofile)

        #根据关系情况,把用户的id插入到sina_user:relation列族中
        mutations = []
        for uid, relation in self.uids.iteritems():
            qualifier = struct.pack('<q', uid)

            user = self.users[uid]
            gender = user['gender']
            vt = user['verified_type']
            vt = verified_type_map.get(vt, vt)
            v = vt << 3
            v |= 4L if gender == 'm' else 0L
            v |= relation

            v <<= 32
            v |= util.now2epoch()

            v = struct.pack('>q', v)
            m = Mutation(column="%s:%s" % (Relation.column_family, qualifier),
                         value=v)
            mutations.append(m)
        key = struct.pack('<q', self.self_uid)

        u_relation = {
            'tableName': Relation.tableName,
            'rowBatches': BatchMutation(row=key, mutations=mutations)
        }
        batches.append(u_relation)

        return batches
Exemple #2
0
    def load(self, status, uid):
        self.uid = int(uid)
        self.qualifier = status.get_key()

        ustatus = 0L

        r_id = getattr(status,'r_id',0)
        if r_id > 0 : ustatus |= 1

        geo = getattr(status,'geo',None)
        if geo is not None : ustatus |= 2

        pics = getattr(status,'pic_urls',None)
        if pics is not None and len(pics)>0: ustatus |= 4
        if status.reposts_count > 0: ustatus |= 8
        if status.comments_count > 0 : ustatus |= 16
        if status.attitudes_count > 0 : ustatus |= 32

        ustatus <<= 32
        ustatus |= util.now2epoch()

        self.mvalue = struct.pack('>q', ustatus)
Exemple #3
0
    def get_batches(self):
        #用于存储需要更新的内容,可能涉及多个表、多个列族
        batches = []

        #根据关系用户,将关系用户的Profile插入到表中
        for uid, user in self.users.iteritems():
            uprofile = UserProfile()
            uprofile.load(user)
            batches_uprofile = uprofile.get_batches()
            batches.extend(batches_uprofile)

        #根据关系情况,把用户的id插入到sina_user:relation列族中
        mutations = []
        for uid,relation in self.uids.iteritems():
            qualifier = struct.pack('<q',uid)

            user = self.users[uid]
            gender = user['gender']
            vt = user['verified_type']
            vt = verified_type_map.get(vt,vt)
            v = vt << 3
            v |= 4L if gender == 'm' else 0L
            v |= relation

            v <<= 32
            v |= util.now2epoch()

            v = struct.pack('>q',v)
            m = Mutation(column="%s:%s" % (Relation.column_family,qualifier), value=v)
            mutations.append(m)
        key = struct.pack('<q',self.self_uid)

        u_relation = {
            'tableName': Relation.tableName,
            'rowBatches': BatchMutation(row=key, mutations=mutations)
        }
        batches.append(u_relation)

        return batches
Exemple #4
0
    def load(self, status, uid):
        self.uid = int(uid)
        self.qualifier = status.get_key()

        ustatus = 0L

        r_id = getattr(status, 'r_id', 0)
        if r_id > 0: ustatus |= 1

        geo = getattr(status, 'geo', None)
        if geo is not None: ustatus |= 2

        pics = getattr(status, 'pic_urls', None)
        if pics is not None and len(pics) > 0: ustatus |= 4
        if status.reposts_count > 0: ustatus |= 8
        if status.comments_count > 0: ustatus |= 16
        if status.attitudes_count > 0: ustatus |= 32

        ustatus <<= 32
        ustatus |= util.now2epoch()

        self.mvalue = struct.pack('>q', ustatus)