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))
Ejemplo n.º 2
0
class TestBuddyLogEntry(unittest.TestCase):

    def setUp(self):
        self.entry = BuddyLogEntry(user_id=USER_ID, buddy_sn='someusername',
            buddy_id=USER_ID + 1, size=((MSGS_USER + MSGS_BUDDY) * 100),
            cumu_msgs_ct=(MSGS_USER + MSGS_BUDDY),
            msgs_user=MSGS_USER, msgs_buddy=MSGS_BUDDY, start_time=START_TIME,
            end_time=END_TIME, timestamp=START_TIME)

    def test_expected_values(self):
        self.assertEqual(END_TIME - START_TIME, self.entry.duration())
        self.assertEqual(MSGS_USER + MSGS_BUDDY, self.entry.msg_ct())

        delta = self.entry.pretty_end_time() - self.entry.pretty_start_time()
        expected_seconds = END_TIME - START_TIME

        self.assertEqual(timedelta(0, expected_seconds), delta)
Ejemplo n.º 3
0
    def update(self, buddy_sns=[]):
        ''' The general 'update' logic for a plotter. Subclasses override
            draw() in order to provide unique behavior.

            @param buddy_sns A list of strings representing buddy screen names.
            '''
        self.current_buddy_sn_list = buddy_sns

        # TODO: decide how we feel about the view looking stuff up in the db
        ble_entries = BuddyLogEntry.get_cumu_logs_for_set(buddy_sns)

        self.figure.clear()
        self.figure.gca().clear()

        if len(buddy_sns) == 0: buddy_sns = ['representative sample']
        self.draw(buddy_sns=buddy_sns, ble_entries=ble_entries)
Ejemplo n.º 4
0
 def setUp(self):
     self.entry = BuddyLogEntry(user_id=USER_ID, buddy_sn='someusername',
         buddy_id=USER_ID + 1, size=((MSGS_USER + MSGS_BUDDY) * 100),
         cumu_msgs_ct=(MSGS_USER + MSGS_BUDDY),
         msgs_user=MSGS_USER, msgs_buddy=MSGS_BUDDY, start_time=START_TIME,
         end_time=END_TIME, timestamp=START_TIME)