Updte to include email count in top senders list

This commit is contained in:
Alex Selimov 2025-04-19 10:34:28 -04:00
parent 88899dfbd4
commit 77ec5ffff1
2 changed files with 13 additions and 5 deletions

View File

@ -59,7 +59,9 @@ def cli():
if len(sender.names) > 5: if len(sender.names) > 5:
names_str += f" and {len(sender.names) - 5} more" names_str += f" and {len(sender.names) - 5} more"
result.append(f"{i}. {sender.email} - Names used: {names_str}") result.append(
f"{i}. {sender.email} - Email count: {sender.count} - Names used: {names_str}"
)
output = "\n".join( output = "\n".join(
[f"Top {len(top_senders)} senders in {maildir_path}:", "=" * 40, *result] [f"Top {len(top_senders)} senders in {maildir_path}:", "=" * 40, *result]

View File

@ -58,11 +58,14 @@ def parse_maildir(path_to_dir: str | Path):
class TopSender: class TopSender:
"""Simple class to store the top sender alongside the first 5 names they used""" """Simple class to store the top sender,
alongisde names they used and the count of emails sent by them
"""
def __init__(self, email: str, names: list[str]): def __init__(self, email: str, names: list[str], count: int):
self.email = email self.email = email
self.names = names self.names = names
self.count = count
class MailDir: class MailDir:
@ -105,11 +108,14 @@ class MailDir:
""" """
unique_senders = self._df["email"].value_counts().iloc[0:n]
senders = [ senders = [
TopSender( TopSender(
email, list(self._df.loc[self._df["email"] == email, "name"].unique()) email,
list(self._df.loc[self._df["email"] == email, "name"].unique()),
count,
) )
for email in self._df["email"].value_counts().iloc[0:n].index for (email, count) in unique_senders.items()
] ]
return senders return senders