Example #1
0
 def write_timeline_to_db(self, msglist):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         cursor = conn.cursor()
         what_to_write = []
         for msg in msglist:
             try:
                 pickled_msg = obj2str(msg)
                 sig = unicode(msg.digest())
                 cursor.execute(
                     "SELECT * FROM home_timeline WHERE digest = ?",
                     (sig, ))
                 if not cursor.fetchone():
                     what_to_write.append(
                         (unicode(pickled_msg), sig, msg.parsed.text,
                          msg.parsed.username, msg.parsed.userid,
                          msg.parsed.time))
             except Exception, e:
                 logger.warning("Error while checking message: %s" %
                                (str(e)))
         try:
             logger.info("Writing %d messages" % (len(what_to_write)))
             cursor.executemany(
                 "INSERT INTO home_timeline (pickled_object, digest, text, username, userid, time) VALUES(?, ?, ?, ?, ?, ?)",
                 what_to_write)
         except Exception, e:
             logger.warning("Error %s" % (str(e)))
Example #2
0
 def _update(self, type, args, kwargs):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         cursor = conn.cursor()
         callback = None
         if 'callback' in kwargs:
             callback = kwargs['callback']
             del kwargs['callback']
         cursor.execute(
             "INSERT INTO pending_update (type, callback, args, kwargs) VALUES (?, ?, ?, ?)",
             (type, obj2str(callback), obj2str(args), obj2str(kwargs)))
         conn.commit()
         cursor.close()
         return True
     except Exception, e:
         logger.warning("Error while saving pending_update: %s" % (str(e)))
         return False
Example #3
0
 def _update(self, type, args, kwargs):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         cursor = conn.cursor()
         callback = None
         if 'callback' in kwargs:
             callback = kwargs['callback']
             del kwargs['callback']
         cursor.execute("INSERT INTO pending_update (type, callback, args, kwargs) VALUES (?, ?, ?, ?)", (
             type,
             obj2str(callback),
             obj2str(args),
             obj2str(kwargs)
         ))
         conn.commit()
         cursor.close()
         return True
     except Exception, e:
         logger.warning("Error while saving pending_update: %s" % (str(e)))
         return False
Example #4
0
 def write_timeline_to_db(self, msglist):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         cursor = conn.cursor()
         what_to_write = [
         ]
         for msg in msglist:
             try:
                 pickled_msg = obj2str(msg)
                 sig = unicode(msg.digest())
                 cursor.execute("SELECT * FROM home_timeline WHERE digest = ?", (sig,))
                 if not cursor.fetchone():
                     what_to_write.append((
                         unicode(pickled_msg), sig, msg.parsed.text, msg.parsed.username, msg.parsed.userid, msg.parsed.time
                     ))
             except Exception, e:
                 logger.warning("Error while checking message: %s" % (str(e)))
         try:
             logger.info("Writing %d messages" % (len(what_to_write)))
             cursor.executemany("INSERT INTO home_timeline (pickled_object, digest, text, username, userid, time) VALUES(?, ?, ?, ?, ?, ?)", what_to_write)
         except Exception, e:
             logger.warning("Error %s" % (str(e)))