Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subs to all topics, specify binary path, logic for all others as json #94

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions gcn_email/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from email.message import EmailMessage
import logging
import os
import json

import boto3
from boto3.dynamodb.conditions import Key
Expand Down Expand Up @@ -64,9 +65,7 @@ def subscribe_to_topics(consumer: Consumer):
# list_topics also contains some non-topic values, filtering is necessary
# 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.')]
topics = [topic for topic in consumer.list_topics().topics]
log.info('Subscribing to topics: %r', topics)
consumer.subscribe(topics)

Expand All @@ -80,10 +79,16 @@ def kafka_message_to_email(message):
email_message.add_attachment(
message.value(), filename='notice.xml',
maintype='application', subtype='xml')
else:
elif topic.startswith('gcn.classic.binary.'):
email_message.add_attachment(
message.value(), filename='notice.bin',
maintype='application', subtype='octet-stream')
else:
message_JSON = message.value().decode()
# Strip out large data fields here...
# ex: del message_JSON['attachments']
email_message.set_content(json.dumps(message_JSON, indent=4))

email_message['Subject'] = topic
return email_message.as_bytes()

Expand Down