Skip to content
Browse files

send CSV file on period reset

  • Loading branch information...
yangmillstheory committed Dec 9, 2017
1 parent 369c7f4 commit 22cda1877bc814a2d176af8973f7557e4793bda7
Showing with 31 additions and 2 deletions.
  1. +31 −2 reset/
@@ -3,9 +3,13 @@
import os
import logging
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication

LOCAL_CSV_PATH = '/tmp/{}'.format(os.getenv('csv_key'))
BUDGET_FILE_NAME = os.environ['csv_key']
RESET_RECIPIENTS = os.getenv('reset_recipients').split(',')
MAX_PERIOD_SPEND = float(os.getenv('max_period_spend'))

@@ -23,6 +27,7 @@ def get_logger():

logger = get_logger()
sns = boto3.client('sns')
ses = boto3.client('ses')
s3 = boto3.client('s3')

@@ -72,11 +77,35 @@ def _notify_period_spend():'Sent summary notification.')

def _send_csv_email():
"""Sends the downloaded CSV file to a list of recipients."""
message = MIMEMultipart()
message['Subject'] = 'Budget Period Log'
message['From'] = ''
with open(LOCAL_CSV_PATH, 'rb') as f:
# yes, read all the bytes into memory; the file is small
attachment = MIMEApplication(
'Content-Disposition', 'attachment', filename=BUDGET_FILE_NAME)
message.attach(attachment)'Sending CSV file to {}'.format(RESET_RECIPIENTS))
'Data': message.as_string(),
})'Email sent.')

def handler(*args):
"""Sends a summary for the current budget, then resets the template."""
"""Sends a summary for the current budget via SMS and email, then resets
the template.
"""'Resetting budget.')
if not os.getenv('dry_run'):
_reset_csv()'Budget reset.')

0 comments on commit 22cda18

Please sign in to comment.
You can’t perform that action at this time.