Skip to content

Commit

Permalink
Fixes formating and check size of all fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota002 committed Jan 30, 2024
1 parent 3f43a69 commit f77efe3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions gcn_email/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import json
import sys

import boto3
from boto3.dynamodb.conditions import Key
Expand Down Expand Up @@ -82,10 +83,12 @@ def kafka_message_to_email(message):
message.value(), filename='notice.xml',
maintype='application', subtype='xml')
elif topic.startswith('gcn.notices.'):
value = json.loads(message.value().decode())
if 'healpix_file' in value:
value['healpix_file'] = 'This content is too large for email. To receive it, see https://gcn.nasa.gov/quickstart'
email_message.set_content(json.dumps(value, indent=4))
valueJson = json.loads(message.value().decode())
for key in valueJson:
if sys.getsizeof(valueJson[key]) > 512:
valueJson[key] = 'This content is too large for email. '\
'To receive it, see https://gcn.nasa.gov/quickstart'
email_message.set_content(json.dumps(valueJson, indent=4))
else:
email_message.add_attachment(
message.value(), filename='notice.bin',
Expand Down

0 comments on commit f77efe3

Please sign in to comment.