-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
49 lines (32 loc) · 1.39 KB
/
server.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
43
44
45
46
47
48
49
import os
import subprocess
from flask import Flask, request, render_template, send_file
from config import BaseConfig
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config.from_object(BaseConfig)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in BaseConfig.ALLOWED_EXTENSIONS
def change_ending(filename, ending):
return "{0}.{1}".format(os.path.splitext(filename)[0], ending)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'file' not in request.files:
return "Invalid request", 400
file = request.files['file']
if not file.filename or file.filename == '':
return "Invalid request", 400
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(filepath)
ofx_filename = change_ending(filename, 'ofx')
ofx_filepath = os.path.join(
app.config['UPLOAD_FOLDER'], ofx_filename)
subprocess.call(["ofxstatement", "convert", "-t",
"op", filepath, ofx_filepath])
return send_file(ofx_filepath, as_attachment=True)
return render_template('index.html')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000)