예제 #1
0
def send_error_message(error_message):
    email_template = os.path.join(templates_directory,
                                  'email_message.html')
    with open(email_template, 'r') as html_template:
        html_template_string = html_template.read()

    css_template = os.path.join(templates_directory, 'email_bootstrap.min.css')
    with open(css_template, 'r') as css:
        css_string = css.read()

    template = Template(html_template_string)

    message = '''
    <div class="alert alert-danger" role="alert">
        {0}
    </div>'''.format(error_message)

    html_body = template.render(title='Error Updating Bank Information',
                                css=css_string,
                                message=message).encode('utf-8')

    html_body = transform(html_body).encode('utf-8')

    msg = Message('Error Updating Bank Information',
                  recipients=[current_app.config['MAIL_USERNAME']],
                  html=html_body)
    mail.send(msg)
예제 #2
0
def send_error_message(error_message):
    email_template = os.path.join(templates_directory, 'email_message.html')
    with open(email_template, 'r') as html_template:
        html_template_string = html_template.read()

    css_template = os.path.join(templates_directory, 'email_bootstrap.min.css')
    with open(css_template, 'r') as css:
        css_string = css.read()

    template = Template(html_template_string)

    message = '''
    <div class="alert alert-danger" role="alert">
        {0}
    </div>'''.format(error_message)

    html_body = template.render(title='Error Updating Bank Information',
                                css=css_string,
                                message=message).encode('utf-8')

    html_body = transform(html_body).encode('utf-8')

    msg = Message('Error Updating Bank Information',
                  recipients=[current_app.config['MAIL_USERNAME']],
                  html=html_body)
    mail.send(msg)
예제 #3
0
def send_ofx_bank_transactions_report():
    start = datetime.now().date() - timedelta(days=1)
    new_transactions = (db.session.query(Transactions.id, Transactions.date, Transactions.amount,
                                         Transactions.description, Transactions.account)
                        .filter(Transactions.date > start)
                        .order_by(Transactions.date.desc()).all())
    if new_transactions:
        header = ['ID', 'Date', 'Amount', 'Description', 'Account']
        transactions = [[cell for cell in row] for row in new_transactions]
        for row in transactions:
            row[0] = '...' + str(row[0])[-4:-1]
            row[1] = row[1].date()
            row[2] = '{0:,.2f}'.format(row[2])
        html_body = results_to_email_template('New Transactions', '', header, transactions)
        msg = Message('New Transactions', recipients=[current_app.config['MAIL_USERNAME']], html=html_body)
        mail.send(msg)
예제 #4
0
def send_ofx_bank_transactions_report():
    start = datetime.now().date() - timedelta(days=1)
    new_transactions = (db.session.query(
        Transactions.id, Transactions.date, Transactions.amount,
        Transactions.description,
        Transactions.account).filter(Transactions.date > start).order_by(
            Transactions.date.desc()).all())
    if new_transactions:
        header = ['ID', 'Date', 'Amount', 'Description', 'Account']
        transactions = [[cell for cell in row] for row in new_transactions]
        for row in transactions:
            row[0] = '...' + str(row[0])[-4:-1]
            row[1] = row[1].date()
            row[2] = '{0:,.2f}'.format(row[2])
        html_body = results_to_email_template('New Transactions', '', header,
                                              transactions)
        msg = Message('New Transactions',
                      recipients=[current_app.config['MAIL_USERNAME']],
                      html=html_body)
        mail.send(msg)
예제 #5
0
def backup_db():
    if platform.system() == 'Linux':
        bash_path = '/bin/bash'
        pg_dump_path = '/usr/bin/pg_dump'
    elif platform.system() == 'Darwin':
        bash_path = '/usr/local/bin/bash'
        pg_dump_path = '/usr/local/bin/pg_dump'
    else:
        return False
    backup_file_name = datetime.now().strftime('%Y%m%d%H%M%S%f') + '.dump'
    backup_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), backup_file_name)
    command = [pg_dump_path,
               '-Fc',
               'pacioli',
               '>', backup_file_path]
    command = [c.encode('utf-8') for c in command]
    command = ' '.join(command)
    subprocess.call(command, shell=True, executable=bash_path)
    msg = Message('Database Backup', recipients=[app.config['MAIL_USERNAME']])
    with app.open_resource(backup_file_path) as fp:
        msg.attach(backup_file_name, 'application/octet-stream', fp.read())
    mail.send(msg)
    os.remove(backup_file_path)
예제 #6
0
def backup_db():
    if platform.system() == 'Linux':
        bash_path = '/bin/bash'
        pg_dump_path = '/usr/bin/pg_dump'
    elif platform.system() == 'Darwin':
        bash_path = '/usr/local/bin/bash'
        pg_dump_path = '/usr/local/bin/pg_dump'
    else:
        return False
    backup_file_name = datetime.now().strftime('%Y%m%d%H%M%S%f') + '.dump'
    backup_file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), backup_file_name)
    command = [pg_dump_path,
               '-Fc',
               'pacioli',
               '>', backup_file_path]
    command = [c.encode('utf-8') for c in command]
    command = ' '.join(command)
    subprocess.call(command, shell=True, executable=bash_path)
    msg = Message('Database Backup', recipients=[app.config['MAIL_USERNAME']])
    with app.open_resource(backup_file_path) as fp:
        msg.attach(backup_file_name, 'application/octet-stream', fp.read())
    mail.send(msg)
    os.remove(backup_file_path)