예제 #1
0
 def delete_follower(self, guid):
     cursor = self.db.cursor()
     f = Followers()
     ser = self.get_followers()
     if ser is not None:
         f.ParseFromString(ser)
         for follower in f.followers:
             if follower.guid == guid:
                 f.followers.remove(follower)
     cursor.execute('''INSERT OR REPLACE INTO followers(id, serializedFollowers) VALUES (?,?)''',
                    (1, f.SerializeToString()))
     self.db.commit()
 def set_follower(self, proto):
     cursor = self.db.cursor()
     f = Followers()
     ser = self.get_followers()
     if ser is not None:
         for follower in f.followers:
             if follower.guid == proto.guid:
                 f.followers.remove(follower)
     f.followers.extend([proto])
     cursor.execute('''INSERT OR REPLACE INTO followers(id, serializedFollowers) VALUES (?,?)''',
                    (1, f.SerializeToString()))
     self.db.commit()
예제 #3
0
 def set_follower(self, proto):
     conn = Database.connect_database(self.PATH)
     with conn:
         cursor = conn.cursor()
         f = Followers()
         ser = self.get_followers()
         if ser is not None:
             f.ParseFromString(ser)
             for follower in f.followers:
                 if follower.guid == proto.guid:
                     f.followers.remove(follower)
         f.followers.extend([proto])
         cursor.execute('''INSERT OR REPLACE INTO followers(id, serializedFollowers) VALUES (?,?)''',
                        (1, f.SerializeToString()))
         conn.commit()
     conn.close()
예제 #4
0
    def get_followers(self, start=0):
        conn = Database.connect_database(self.PATH)
        cursor = conn.cursor()

        cursor.execute('''SELECT Count(*) FROM followers''')
        count = cursor.fetchone()[0]

        f = Followers()
        if count > 0:
            smt = '''select serializedFollower from followers order by rowid desc limit 30 offset ''' + str(start)
            cursor.execute(smt)
            serialized_followers = cursor.fetchall()
            conn.close()
            for proto in serialized_followers:
                p = Followers.Follower()
                p.ParseFromString(proto[0].decode("hex"))
                f.followers.extend([p])
        return (f.SerializeToString(), count)