-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.py
42 lines (37 loc) · 1.74 KB
/
webapp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from flask import Flask
from flask import render_template, flash, request, redirect
import os
from werkzeug.utils import secure_filename
import tempfile
from funding_earnings_stats import FundingEarningsCalculator
app = Flask(__name__)
app.secret_key = os.urandom(24)
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ['csv']
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
if 'file' not in request.files:
flash('No file part')
file = request.files['file']
if file.filename == '':
flash('No selected file')
if not (allowed_file(file.filename)):
flash("Unsupported filetype")
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
target_path = os.path.join(os.path.join(tempfile.gettempdir(), filename))
file.save(target_path)
calc = FundingEarningsCalculator(target_path)
currency_stats_tables = []
for currency, dataframe in calc.get_currency_stats().items():
currency_stats_tables.append((
currency,
dataframe.to_html(classes=['table table-striped']).replace('border="1"', 'border="0"').replace(
'border="1"', 'border="0"')))
monthly_earnings_table = calc.get_monthly_earnings().to_html(
classes=['table table-striped']).replace('border="1"', 'border="0"')
return render_template('show_stats.html', monthly_earnings=monthly_earnings_table,currency_stats=currency_stats_tables)
return render_template('choose_file.html')