From 13cf823a7981a07fc734759f29ef06da53a3e782 Mon Sep 17 00:00:00 2001 From: proffapt Date: Sun, 24 Nov 2024 00:44:59 +0530 Subject: [PATCH] feat: store body and attachment in db as well --- mftp/mail.py | 3 +++ mftp/ntfy.py | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mftp/mail.py b/mftp/mail.py index c219b1f..1ff05bc 100644 --- a/mftp/mail.py +++ b/mftp/mail.py @@ -78,6 +78,7 @@ def format_notice(notices, session): try: body = parseBody(session, year, id_) + notice['Body'] = body except Exception as e: logging.error(f" Failed to parse mail body ~ {str(e)}") break @@ -115,6 +116,8 @@ def format_notice(notices, session): break if len(attachment) != 0: + notice['Attachment'] = attachment + file = MIMEBase('application', 'octet-stream') file.set_payload(attachment) encoders.encode_base64(file) diff --git a/mftp/ntfy.py b/mftp/ntfy.py index 7363d7d..cb76b01 100644 --- a/mftp/ntfy.py +++ b/mftp/ntfy.py @@ -52,6 +52,7 @@ def format_notice(notices, session): try: data = parseBody(notice, session, year, id_) + notice['Body'] = data body, links = parseLinks(data) body += ''' -------------- @@ -90,6 +91,8 @@ def format_notice(notices, session): break if len(attachment) != 0: + notice['Attachment'] = attachment + file_name = notification['Attachment'] if save_file(file_name, attachment): notification['Attachment'] = file_name @@ -104,6 +107,7 @@ def format_notice(notices, session): def send(notifications, notice_db): + print('[SENDING NOTIFICATIONS]', flush=True) for notif in notifications: notification = notif.get('formatted_notice') @@ -116,9 +120,6 @@ def send(notifications, notice_db): if len(latest_successful_subscribers) != 0: ntfy_topics = [subscirber for subscirber in ntfy_topics if subscirber not in latest_successful_subscribers] - if ntfy_topics: - print('[SENDING NOTIFICATIONS]', flush=True) - for ntfy_topic in ntfy_topics: try: query_params = f"message={quote(notification['Body'])}"