Ejemplo n.º 1
0
    def update_from_logs(self):
        """ Looks at the last processed conversation we have on this user, and
            grabs any updated log files if needed. """
        conn = self.get_connection()

        for username in os.listdir(self.path):
            if username[0] == '.': continue
            cur = conn.cursor()
            cur.execute('''select max(timestamp) from conversations inner join
                        users on users.id = conversations.buddy_id where
                        users.screenname = ? limit 1''', (username,))
            ts = cur.fetchone()
            if ts is None:
                last_file_ts = 0
            else:
                last_file_ts = ts[0]

            if last_file_ts >= os.stat(join(self.path, username)).st_mtime:
                continue
            print 'updating db for '+username

            for root, dirs, files in os.walk(join(self.path, username)):
                if not files: continue # empty dir
                for name in files:
                    if name.find('.swp') > -1: continue
                    if last_file_ts >= os.stat(join(root, name)).st_mtime:
                        continue
                    user_id = self.get_user_id(self.get_current_sn())
                    buddy_id = self.get_user_id(username)
                    BuddyLogEntry.create(conn, self.get_current_sn(),
                                         user_id, buddy_id, join(root, name))