From 5870303c74996ad70a008ecce27d2f780f7b720b Mon Sep 17 00:00:00 2001 From: Cyberes Date: Wed, 6 Mar 2024 00:18:41 -0700 Subject: [PATCH] add more info to sync history --- iarchiver/database.py | 6 +++--- run.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iarchiver/database.py b/iarchiver/database.py index c267f10..f33f0df 100644 --- a/iarchiver/database.py +++ b/iarchiver/database.py @@ -30,7 +30,7 @@ class EmailDatabase: self.conn = sqlite3.connect(filepath) cursor = self.conn.cursor() cursor.execute(f'CREATE TABLE IF NOT EXISTS folders_mapping (name TEXT UNIQUE, table_name TEXT UNIQUE)') - cursor.execute(f'CREATE TABLE IF NOT EXISTS syncs (timestamp INTEGER UNIQUE, type TEXT)') + cursor.execute(f'CREATE TABLE IF NOT EXISTS syncs (timestamp INTEGER UNIQUE, type TEXT, new_emails INTEGER, new_attachments INTEGER, new_folders INTEGER, duration INTEGER)') self.conn.commit() cursor.close() @@ -64,10 +64,10 @@ class EmailDatabase: cursor.close() return new_email - def finish_sync(self, sync_type: str): + def finish_sync(self, sync_type: str, new_emails: int, new_attachments: int, duration: int): now = int(time.time()) cursor = self.conn.cursor() - cursor.execute('INSERT INTO syncs (timestamp, type) VALUES (?, ?)', (now, sync_type)) + cursor.execute('INSERT INTO syncs (timestamp, type, new_emails, new_attachments, duration) VALUES (?, ?, ?, ?, ?)', (now, sync_type, new_emails, new_attachments, duration)) self.conn.commit() cursor.close() return now diff --git a/run.py b/run.py index 84c3d50..fd305c4 100755 --- a/run.py +++ b/run.py @@ -68,10 +68,10 @@ def main(args): if len(attachments): new_attachments += 1 - database.finish_sync('refresh' if not did_full_sync else 'full') - elapsed = datetime.now() - sync_start_time - logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails.') + database.finish_sync('refresh' if not did_full_sync else 'full', new_emails, new_attachments, int(elapsed.total_seconds())) + + logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails and {new_attachments} attachments.') if __name__ == '__main__':