-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |