parse_py / app.py
broadfield-dev's picture
Create app.py
107a11e verified
raw
history blame
839 Bytes
# app.py
from flask import Flask, request, render_template
from parser import parse_python_file
import os
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'file' not in request.files:
return 'No file uploaded', 400
file = request.files['file']
if file.filename == '' or not file.filename.endswith('.py'):
return 'Invalid file type. Please upload a Python file.', 400
file_path = os.path.join('uploads', file.filename)
file.save(file_path)
parts = parse_python_file(file_path)
return render_template('results.html', parts=parts)
return render_template('upload.html')
if __name__ == '__main__':
if not os.path.exists('uploads'):
os.makedirs('uploads')
app.run(port=7860)