From 73341c1bc9eadb0dfc99a64a5bfd367487a3e875 Mon Sep 17 00:00:00 2001 From: Caleb Evans Date: Tue, 5 Mar 2024 20:38:53 -0800 Subject: [PATCH] Add audio message count to attachment totals analyzer --- ica/analyzers/attachment_totals.py | 1 + ica/analyzers/totals_by_day.py | 2 +- ica/queries/attachments.sql | 4 +++- ica/queries/messages.sql | 1 + tests/data/dbs/chats/attachment.json | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ica/analyzers/attachment_totals.py b/ica/analyzers/attachment_totals.py index 78aedca..ae8cade 100644 --- a/ica/analyzers/attachment_totals.py +++ b/ica/analyzers/attachment_totals.py @@ -40,6 +40,7 @@ def main() -> None: .count() .item() ), + "audio_messages": (dfs.attachments["filename"].str.endswith(".caf").sum()), "recorded_videos": (dfs.attachments["mime_type"].eq("video/quicktime").sum()), } ica.output_results( diff --git a/ica/analyzers/totals_by_day.py b/ica/analyzers/totals_by_day.py index 5b86497..c069039 100644 --- a/ica/analyzers/totals_by_day.py +++ b/ica/analyzers/totals_by_day.py @@ -19,7 +19,7 @@ def main() -> None: ) ica.output_results( ( - dfs.messages + dfs.messages[["text", "is_from_me", "datetime", "is_reaction"]] # Count all "text" column values by converting them to integers # (always 1), because resampling the DataFrame will remove all # non-numeric columns diff --git a/ica/queries/attachments.sql b/ica/queries/attachments.sql index b0502e1..f347909 100644 --- a/ica/queries/attachments.sql +++ b/ica/queries/attachments.sql @@ -1,4 +1,6 @@ -SELECT "mime_type" +SELECT "mime_type", + "filename", + "message_id" FROM "attachment" INNER JOIN "message_attachment_join" ON "attachment"."ROWID" = "attachment_id" diff --git a/ica/queries/messages.sql b/ica/queries/messages.sql index d336d38..cdff017 100644 --- a/ica/queries/messages.sql +++ b/ica/queries/messages.sql @@ -1,4 +1,5 @@ SELECT + "ROWID", "text", "attributedBody", datetime("message"."date" / 1000000000 + strftime("%s", "2001-01-01") ,"unixepoch") as "datetime", diff --git a/tests/data/dbs/chats/attachment.json b/tests/data/dbs/chats/attachment.json index 4298009..cf54031 100644 --- a/tests/data/dbs/chats/attachment.json +++ b/tests/data/dbs/chats/attachment.json @@ -1,6 +1,7 @@ [ { "ROWID": "caa5c5fd-f301-4104-b0c4-934f2e52992b", + "filename": "abc.gif", "mime_type": "image/gif" } ]