From 7969822a47b2ac9f17698b70f66c52a12cfa9c89 Mon Sep 17 00:00:00 2001 From: dakota002 Date: Wed, 31 Jan 2024 09:44:10 -0500 Subject: [PATCH] More formatting and accidental fix --- gcn_email/core.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/gcn_email/core.py b/gcn_email/core.py index 4c744e7..952c348 100644 --- a/gcn_email/core.py +++ b/gcn_email/core.py @@ -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__) @@ -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(): @@ -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) @@ -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() @@ -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}})