コード例 #1
0
    def send(self, enterprise_report_file_name):
        """
        Send the given file with the configured information.
        """
        # create a password encrypted zip file
        LOGGER.info('Encrypting data report for {}'.format(
            self.enterprise_customer_name))
        data_report_zip_name = compress_and_encrypt(
            enterprise_report_file_name, self.password)

        data_report_subject = self.REPORT_EMAIL_SUBJECT.format(
            enterprise_name=self.enterprise_customer_name)

        # email the file to the email address(es) in the configuration
        LOGGER.info('Sending encrypted data to {}'.format(
            self.enterprise_customer_name))
        try:
            send_email_with_attachment(data_report_subject,
                                       self.REPORT_EMAIL_BODY,
                                       self.REPORT_EMAIL_FROM_EMAIL,
                                       self.email, data_report_zip_name)
            LOGGER.info(
                'Email report with encrypted zip successfully sent to {} for {}'
                .format(', '.join(self.email), self.enterprise_customer_name))
        except SMTPException:
            LOGGER.exception('Failed to send email report to {} for {}'.format(
                self.email, self.enterprise_customer_name))
def generate_and_email_report():
    """
    Generates a report an sends it as an email with an attachment
    """
    LOGGER.info("Querying Course Graph DB...")
    raw_results = query_coursegraph()

    LOGGER.info("Processing {} html blobs returned...".format(
        len(raw_results)))
    processed_results = process_results(raw_results)

    LOGGER.info("Generating spreadsheet...")
    csv_string = generate_csv_string(processed_results)

    subject = 'External Resource Link Report'
    body = '''Dear Customer Success,
Find attached a file containing course keys and their respective
external resource links.

If you have any questions/concerns with the report, please ask the
Enterprise Team (kindly)!

Sincerely,
The Enterprise Team'''

    from_email = os.environ.get('SEND_EMAIL_FROM')
    filename = 'external-resource-link-report-{}.csv'.format(str(date.today()))

    LOGGER.info("Emailing spreadsheet...")
    send_email_with_attachment(subject,
                               body,
                               from_email,
                               TO_EMAILS.split(','),
                               filename,
                               attachment_data=csv_string.encode('utf-8'))
コード例 #3
0
def generate_and_email_report():
    """
    Generates a report an sends it as an email with an attachment
    """

    from_email = os.environ.get('SEND_EMAIL_FROM')
    today = str(date.today())
    subject = 'External Resource Link Report'
    body = '''Dear Customer Success,
Find attached a file containing course keys and their respective
external resource links.

If you have any questions/concerns with the report, please ask the
Enterprise Team!

Sincerely,
The Enterprise Team'''

    LOGGER.info("Querying Course Graph DB...")
    raw_results = query_coursegraph()

    # Results are too large to send in 1 email (~10MB is the limit) so
    # we split up the results into two parts
    processed_results = process_coursegraph_results(raw_results)
    result_dicts = split_up_results(processed_results)

    for index, result in enumerate(result_dicts):
        readable_number = index + 1

        LOGGER.info(
            "Generating aggregate external links spreadsheet part %s..." % readable_number
        )
        aggregate_report_data = create_csv_string(
            result,
            AGGREGATE_REPORT_CSV_HEADER_ROW,
            create_columns_for_aggregate_report
        )
        filename = 'external-resource-domain-report-part{}-{}.csv'.format(
            readable_number,
            today,
        )
        attachment_data = {filename: aggregate_report_data.encode('utf-8')}

        LOGGER.info(
            "Emailing aggregate spreadsheet part %s..." % readable_number
        )
        send_email_with_attachment(
            subject,
            body,
            from_email,
            TO_EMAILS.split(','),
            attachment_data
        )
コード例 #4
0
def generate_and_email_report():
    """
    Generates a report an sends it as an email with an attachment
    """
    LOGGER.info("Querying Course Graph DB...")
    raw_results = query_coursegraph()
    processed_results = process_coursegraph_results(raw_results)

    LOGGER.info("Generating exhaustive external links spreadsheet...")
    exhaustive_report = create_csv_string(
        processed_results,
        EXHAUSTIVE_REPORT_CSV_HEADER_ROW,
        create_columns_for_exhaustive_report,
    )

    LOGGER.info("Generating aggregate external links spreadsheet...")
    aggregate_report = create_csv_string(
        processed_results,
        AGGREGATE_REPORT_CSV_HEADER_ROW,
        create_columns_for_aggregate_report
    )

    today = str(date.today())
    filenames = [
        'external-resource-link-report-{}.csv'.format(today),
        'external-resource-domain-report-{}.csv'.format(today)
    ]
    attachment_data = {
        filenames[0]: exhaustive_report.encode('utf-8'),
        filenames[1]: aggregate_report.encode('utf-8'),
    }

    subject = 'External Resource Link Report'
    body = '''Dear Customer Success,
Find attached a file containing course keys and their respective
external resource links.

If you have any questions/concerns with the report, please ask the
Enterprise Team (kindly)!

Sincerely,
The Enterprise Team'''

    from_email = os.environ.get('SEND_EMAIL_FROM')

    LOGGER.info("Emailing spreadsheets...")
    send_email_with_attachment(
        subject,
        body,
        from_email,
        TO_EMAILS.split(','),
        attachment_data
    )
コード例 #5
0
 def send(self, files):
     """Send the given files in zip format through SMTP."""
     attachment_data = {super().send(files): None}
     LOGGER.info('Emailing encrypted data as a ZIP to {}'.format(
         self.enterprise_customer_name))
     try:
         send_email_with_attachment(
             self.REPORT_EMAIL_SUBJECT.format(
                 enterprise_name=self.enterprise_customer_name),
             self.REPORT_EMAIL_BODY.format(type=self.data_type),
             self.REPORT_EMAIL_FROM_EMAIL, self.email, attachment_data)
     except SMTPException:
         LOGGER.exception('Failed to send email report to {} for {}'.format(
             self.email, self.enterprise_customer_name))
     else:
         LOGGER.info(
             'Email report with encrypted zip successfully sent to {} for {}'
             .format(self.email, self.enterprise_customer_name))
コード例 #6
0
    def send_enterprise_report(self):
        """
        Query the data warehouse (vertica) and export data to a csv file.

        This file will get encrypted and emailed to the Enterprise Customer.
        """
        enterprise_customer_name = self.reporting_config[
            'enterprise_customer']['name']

        LOGGER.info('Starting process to send email report to {}'.format(
            enterprise_customer_name))

        # initialize base csv file and file writer
        data_report_file_name, data_report_file_writer = self._create_data_report_csv_writer(
        )

        # query vertica and write each row to the file
        LOGGER.debug('Querying Vertica for data for {}'.format(
            enterprise_customer_name))
        data_report_file_writer.writerows(self._query_vertica())

        # create a password encrypted zip file
        LOGGER.debug(
            'Encrypting data report for {}'.format(enterprise_customer_name))
        data_report_zip_name = compress_and_encrypt(
            data_report_file_name,
            decrypt_string(self.reporting_config['password'],
                           self.reporting_config['initialization_vector']))

        # email the file to the email address in the configuration
        LOGGER.debug(
            'Sending encrypted data to {}'.format(enterprise_customer_name))
        try:
            send_email_with_attachment(self.REPORT_EMAIL_SUBJECT,
                                       self.REPORT_EMAIL_BODY,
                                       self.REPORT_EMAIL_FROM_EMAIL,
                                       self.reporting_config['email'],
                                       data_report_zip_name)
        except SMTPException:
            LOGGER.exception(
                'Failed to send email for {}'.format(enterprise_customer_name))

        self._cleanup()