Esempio n. 1
0
 def update_func(self):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         conn.row_factory = sqlite3.Row
         cursor = conn.cursor()
         cursor.execute("SELECT * FROM pending_update")
         i = cursor.fetchone()
         if i:
             cursor.execute("DELETE FROM pending_update WHERE id = ?",
                            (i['id'], ))
             j = {
                 'id': str(i['id']),
                 'args': str2obj(str(i['args'])),
                 'kwargs': str2obj(str(i['kwargs'])),
                 'type': str(i['type']),
                 'callback': str2obj(str(i['callback']))
             }
             res = getattr(self.sp, j['type'])(*j['args'], **j['kwargs'])
             if j['callback']:
                 j['callback'](self, res)
         conn.commit()
         cursor.close()
     except Exception, e:
         logger.warning("Error while updating: %s" % (str(e)))
Esempio n. 2
0
 def update_func(self):
     logger.debug("acquiring lock")
     self.dblock.acquire()
     try:
         conn = sqlite3.connect(self.sqlitefile)
         conn.row_factory = sqlite3.Row
         cursor = conn.cursor()
         cursor.execute("SELECT * FROM pending_update")
         i = cursor.fetchone()
         if i:
             cursor.execute("DELETE FROM pending_update WHERE id = ?", (i['id'], ))
             j = {
                 'id': str(i['id']),
                 'args': str2obj(str(i['args'])),
                 'kwargs': str2obj(str(i['kwargs'])),
                 'type': str(i['type']),
                 'callback': str2obj(str(i['callback']))
             }
             res = getattr(self.sp, j['type'])(*j['args'], **j['kwargs'])
             if j['callback']:
                 j['callback'](self, res)
         conn.commit()
         cursor.close()
     except Exception, e:
         logger.warning("Error while updating: %s" % (str(e)))
Esempio n. 3
0
    def from_repr(repr_str, keys=["label", "rule"], sentence=None, **kwargs):
        """
        Inverse of __repr__ - Creates a new SentenceGraph from a textual representations.
        The representation is in the format (example):
        "Mr. Ittleson is executive , special projects , at CIT Group Holdings Inc. .
         (u'Mr.', u'projects', u'What is Mr.?#9', 'maxCover')
         (u'Mr.', u'CIT Group Holdings Inc.', u'Where is Mr. at?#14', 'singleWord')
         (u'Ittleson', u'projects', u'What is Ittleson to do?#13', 'posForPairs')
         (u'Ittleson', u'CIT Group Holdings Inc.', u'Where was Ittleson?#10', 'singleWord')"

        :param repr_str: 
        :param keys: specify the keys of the 3rd, 4th, ... elements in each edge-tuple.
        :param sentence: if not specified (default), read first line of repr_str as sentence.
        Otherwise, take sentence from argument and read repr_str as textual list of edges.
        :param kwargs: 
        :return: a new SentenceGraph object
        """
        # retrieve sentence and seperate it from rest of representation
        repr_str = repr_str.strip()
        if not sentence:
            sentence = repr_str.splitlines()[0]
            repr_str = '\n'.join(repr_str.splitlines()[1:])
        edgeList = [
            utils.str2obj(line.strip()) for line in repr_str.splitlines()
        ]
        return SentenceGraph.from_edges(sentence,
                                        edgeList,
                                        edge_keys=keys,
                                        **kwargs)
Esempio n. 4
0
 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)))
Esempio n. 5
0
 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)))