Skip to content

Commit

Permalink
More formatting and accidental fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota002 committed Jan 31, 2024
1 parent 770b215 commit 7969822
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions gcn_email/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SENDER = f'GCN Notices <{os.environ["EMAIL_SENDER"]}>'

# Maximum send rate
MAX_SENDS = boto3.client('sesv2').get_send_quota()['MaxSendRate']
MAX_SENDS = boto3.client('ses').get_send_quota()['MaxSendRate']

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,13 +70,13 @@ def query_and_project_subscribers(table, topic):
IndexName='byTopic',
ProjectionExpression="#topic, recipient",
ExpressionAttributeNames={"#topic": "topic"},
KeyConditionExpression=(Key('topic').eq(topic)),
KeyConditionExpression=(Key('topic').eq(topic))
)
except Exception:
log.exception('Failed to query recipients')
return []
else:
return [x["recipient"] for x in response["Items"]]
return [x['recipient'] for x in response['Items']]


def connect_as_consumer():
Expand All @@ -90,7 +90,8 @@ def subscribe_to_topics(consumer: Consumer):
# This may need to be updated if new topics have a format different than
# 'gcn.classic.[text | voevent | binary].[topic]'
topics = [
topic for topic in consumer.list_topics().topics if topic.startswith('gcn.')
topic for topic in consumer.list_topics().topics
if topic.startswith('gcn.')
]
log.info('Subscribing to topics: %r', topics)
consumer.subscribe(topics)
Expand All @@ -103,22 +104,16 @@ def kafka_message_to_email(message):
email_message.set_content(message.value().decode())
elif topic.startswith('gcn.classic.voevent.'):
email_message.add_attachment(
message.value(),
filename='notice.xml',
maintype='application',
subtype='xml',
)
message.value(), filename='notice.xml',
maintype='application', subtype='xml')
elif topic.startswith('gcn.notices.'):
valueJson = json.loads(message.value().decode())
replace_long_values(valueJson, 512)
email_message.set_content(json.dumps(valueJson, indent=4))
else:
email_message.add_attachment(
message.value(),
filename='notice.bin',
maintype='application',
subtype='octet-stream',
)
message.value(), filename='notice.bin',
maintype='application', subtype='octet-stream')
email_message['Subject'] = topic
return email_message.as_bytes()

Expand Down Expand Up @@ -166,5 +161,4 @@ def send_raw_ses_message_to_recipient(bytes, recipient):
SESV2.send_email(
FromEmailAddress=SENDER,
Destination={'ToAddresses': [recipient]},
Content={'Raw': {'Data': bytes}},
)
Content={'Raw': {'Data': bytes}})

0 comments on commit 7969822

Please sign in to comment.