broadfield-dev commited on
Commit
107a11e
·
verified ·
1 Parent(s): 5a58620

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from flask import Flask, request, render_template
3
+ from parser import parse_python_file
4
+ import os
5
+
6
+ app = Flask(__name__)
7
+
8
+ @app.route('/', methods=['GET', 'POST'])
9
+ def index():
10
+ if request.method == 'POST':
11
+ if 'file' not in request.files:
12
+ return 'No file uploaded', 400
13
+
14
+ file = request.files['file']
15
+
16
+ if file.filename == '' or not file.filename.endswith('.py'):
17
+ return 'Invalid file type. Please upload a Python file.', 400
18
+
19
+ file_path = os.path.join('uploads', file.filename)
20
+ file.save(file_path)
21
+
22
+ parts = parse_python_file(file_path)
23
+ return render_template('results.html', parts=parts)
24
+
25
+ return render_template('upload.html')
26
+
27
+ if __name__ == '__main__':
28
+ if not os.path.exists('uploads'):
29
+ os.makedirs('uploads')
30
+ app.run(port=7860)