Skip to content

Commit

Permalink
feat: store body and attachment in db as well
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Nov 23, 2024
1 parent da0dff3 commit 13cf823
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions mftp/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions mftp/ntfy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def format_notice(notices, session):

try:
data = parseBody(notice, session, year, id_)
notice['Body'] = data
body, links = parseLinks(data)
body += '''
--------------
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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'])}"
Expand Down

0 comments on commit 13cf823

Please sign in to comment.