Exemple #1
0
 def __init__(self,
              pocket,
              sqlite,
              callback=_default_callback,
              timeline_sleep=60,
              update_sleep=10):
     self.sp = pocket
     self.dblock = thread.allocate_lock()
     self.sqlitefile = sqlite
     conn = sqlite3.connect(self.sqlitefile)
     c = conn.cursor()
     c.execute("""CREATE TABLE IF NOT EXISTS home_timeline (
         id integer primary key, pickled_object text, digest text, text text, username text, userid text, time integer, isread integer DEFAULT 0
     )""")
     c.execute("""CREATE TABLE IF NOT EXISTS pending_update (
         id integer primary key, callback text, type text, args text, kwargs text
     )""")
     conn.commit()
     c.close()
     self.home_timeline_job = AsyncDaemonWithCallBack(
         self.sp.home_timeline, (), {}, self.write_timeline_to_db,
         timeline_sleep)
     self.update_job = AsyncDaemonWithCallBack(self.update_func, (), {},
                                               None, update_sleep)
     self.home_timeline_job.start()
     self.update_job.start()
Exemple #2
0
class BackgroundOperationPocketWithSQLite:
    def __init__(self, pocket, sqlite, callback=_default_callback, timeline_sleep=60, update_sleep=10):
        self.sp = pocket
        self.dblock = thread.allocate_lock()
        self.sqlitefile = sqlite
        conn = sqlite3.connect(self.sqlitefile)
        c = conn.cursor()
        c.execute("""CREATE TABLE IF NOT EXISTS home_timeline (
            id integer primary key, pickled_object text, digest text, text text, username text, userid text, time integer, isread integer DEFAULT 0
        )""")
        c.execute("""CREATE TABLE IF NOT EXISTS pending_update (
            id integer primary key, callback text, type text, args text, kwargs text
        )""")
        conn.commit()
        c.close()
        self.home_timeline_job = AsyncDaemonWithCallBack(self.sp.home_timeline, (), {}, self.write_timeline_to_db, timeline_sleep)
        self.update_job = AsyncDaemonWithCallBack(self.update_func, (), {}, None, update_sleep)
        self.home_timeline_job.start()
        self.update_job.start()

    def home_timeline(self, count=20):
        ret = snstype.MessageList()
        logger.debug("acquiring lock")
        self.dblock.acquire()
        try:
            conn = sqlite3.connect(self.sqlitefile)
            c = conn.cursor()
            c.execute("SELECT pickled_object FROM home_timeline ORDER BY time DESC LIMIT 0, %d" % (count,))
            p = c.fetchall()
            logger.info("%d messages read from database" % (len(p)))
            for i in p:
                ret.append(str2obj(str(i[0])))
        except Exception, e:
            logger.warning("Error while reading database: %s" % (str(e)))
        finally:
Exemple #3
0
class BackgroundOperationPocketWithSQLite:
    def __init__(self,
                 pocket,
                 sqlite,
                 callback=_default_callback,
                 timeline_sleep=60,
                 update_sleep=10):
        self.sp = pocket
        self.dblock = thread.allocate_lock()
        self.sqlitefile = sqlite
        conn = sqlite3.connect(self.sqlitefile)
        c = conn.cursor()
        c.execute("""CREATE TABLE IF NOT EXISTS home_timeline (
            id integer primary key, pickled_object text, digest text, text text, username text, userid text, time integer, isread integer DEFAULT 0
        )""")
        c.execute("""CREATE TABLE IF NOT EXISTS pending_update (
            id integer primary key, callback text, type text, args text, kwargs text
        )""")
        conn.commit()
        c.close()
        self.home_timeline_job = AsyncDaemonWithCallBack(
            self.sp.home_timeline, (), {}, self.write_timeline_to_db,
            timeline_sleep)
        self.update_job = AsyncDaemonWithCallBack(self.update_func, (), {},
                                                  None, update_sleep)
        self.home_timeline_job.start()
        self.update_job.start()

    def home_timeline(self, count=20):
        ret = snstype.MessageList()
        logger.debug("acquiring lock")
        self.dblock.acquire()
        try:
            conn = sqlite3.connect(self.sqlitefile)
            c = conn.cursor()
            c.execute(
                "SELECT pickled_object FROM home_timeline ORDER BY time DESC LIMIT 0, %d"
                % (count, ))
            p = c.fetchall()
            logger.info("%d messages read from database" % (len(p)))
            for i in p:
                ret.append(str2obj(str(i[0])))
        except Exception, e:
            logger.warning("Error while reading database: %s" % (str(e)))
        finally:
Exemple #4
0
 def __init__(self, pocket, sqlite, callback=_default_callback, timeline_sleep=60, update_sleep=10):
     self.sp = pocket
     self.dblock = thread.allocate_lock()
     self.sqlitefile = sqlite
     conn = sqlite3.connect(self.sqlitefile)
     c = conn.cursor()
     c.execute("""CREATE TABLE IF NOT EXISTS home_timeline (
         id integer primary key, pickled_object text, digest text, text text, username text, userid text, time integer, isread integer DEFAULT 0
     )""")
     c.execute("""CREATE TABLE IF NOT EXISTS pending_update (
         id integer primary key, callback text, type text, args text, kwargs text
     )""")
     conn.commit()
     c.close()
     self.home_timeline_job = AsyncDaemonWithCallBack(self.sp.home_timeline, (), {}, self.write_timeline_to_db, timeline_sleep)
     self.update_job = AsyncDaemonWithCallBack(self.update_func, (), {}, None, update_sleep)
     self.home_timeline_job.start()
     self.update_job.start()