This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def squared(x): | |
return x**2 | |
def test_squared(): | |
assert squared(3) == 9 | |
assert squared(3) == 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pdfkit | |
for i in range(1,11): | |
pdfkit.from_file(str(i) + '.html', str(i) + '.pdf') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jinja2 | |
templateLoader = jinja2.FileSystemLoader(searchpath="./") | |
templateEnv = jinja2.Environment(loader=templateLoader) | |
TEMPLATE_FILE = "pdf_interest_report.html" | |
template = templateEnv.get_template(TEMPLATE_FILE) | |
for d in data_frames: | |
outputText = template.render(df=d['df'], | |
interest_rate=d['interest_rate']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
interest_rates = [i*.01 for i in range(1,11)] | |
initial_account_sizes = [100, 500, 20000, 50000] | |
data_frames = [] | |
for interest_rate in interest_rates: | |
df = {} | |
for initial_account_size in initial_account_sizes: | |
df['Account Size: ' + str(initial_account_size)] = [initial_account_size * (1 + interest_rate) ** year for year in range(1, 21)] | |
df = pd.DataFrame(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jinja2 | |
templateLoader = jinja2.FileSystemLoader(searchpath="./") | |
templateEnv = jinja2.Environment(loader=templateLoader) | |
TEMPLATE_FILE = "name.txt" | |
template = templateEnv.get_template(TEMPLATE_FILE) | |
outputText = template.render(name='Mark') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head></head> | |
<body> | |
<h1>Interest Rate: {{ interest_rate * 100 }}%</h1> | |
<table> | |
<tr> | |
{% for column in df.columns %} | |
<th>{{ column }}</th> | |
{% endfor %} | |
</tr> | |
{% for idx, row in df.iterrows() %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, render_template, Blueprint | |
from .forms import NameForm | |
from .models import Name | |
from . import db | |
bp = Blueprint('app', __name__) | |
@bp.route('/', methods=['GET', 'POST']) | |
def home(): | |
form = NameForm() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Hello World!</h1> | |
<br> | |
<h3>Please enter a name:</h3> | |
<form method=post> | |
{{ form.csrf_token }} | |
{{ form.name.label }} | |
{{ form.name}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask_wtf import FlaskForm | |
from wtforms import StringField, SubmitField | |
from wtforms.validators import DataRequired | |
class NameForm(FlaskForm): | |
name = StringField('Enter a name', validators=[DataRequired()]) | |
submit = SubmitField('Submit') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from app import create_app | |
app = create_app(os.getenv('FLASK_CONFIG') or 'default') |