Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZORO2045 authored Apr 11, 2024
1 parent d364937 commit 59e26d4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from flask import Flask, render_template, request, send_file
from autopep8 import fix_code

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload_file():
file = request.files['file']
file_type = request.form['fileType']

if file and (file_type == 'python' or file_type == 'php'):
content = file.read().decode('utf-8')
corrected_content = fix_code(content)
corrected_filename = file.filename.replace('.py', '_corrected.py').replace('.php', '_corrected.php')

with open(corrected_filename, 'w') as corrected_file:
corrected_file.write(corrected_content)

return send_file(corrected_filename, as_attachment=True)
else:
return "Invalid file or file type."

if __name__ == '__main__':
app.run(debug=True)
27 changes: 27 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>File Correction Bot</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Choose the type of file you want to correct:</p>
<button onclick="selectFileType('python')">Python 🐍</button>
<button onclick="selectFileType('php')">PHP 🐘</button>

<form id="fileForm" action="/upload" method="post" enctype="multipart/form-data" style="display:none;">
<input type="file" name="file" id="fileInput">
<input type="hidden" name="fileType" id="fileTypeInput">
<input type="submit" value="Upload">
</form>

<script>
function selectFileType(fileType) {
document.getElementById('fileTypeInput').value = fileType;
document.getElementById('fileInput').click();
}
</script>
</body>
</html>

0 comments on commit 59e26d4

Please sign in to comment.