Skip to content
Snippets Groups Projects
Commit e6f9ac6e authored by Ziyan Lu's avatar Ziyan Lu
Browse files

ziyan

parent 73e78381
No related branches found
No related tags found
No related merge requests found
File moved
from flask import Flask, render_template, request, redirect, flash
from werkzeug.utils import secure_filename
import os
app = Flask(__name__)
app.secret_key = 'some_secret_key'
app.config['UPLOAD_DIRECTORY'] = 'uploads/'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 * 1024
app.config['ALLOWED_EXTENSIONS'] = ['.txt', '.py', '.word']
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods = ['POST'])
def upload():
file = request.files['file']
extension = os.path.splitext(file.filename)[1].lower()
if file:
if extension not in app.config['ALLOWED_EXTENSIONS']:
flash("Please upload word file or py file")
else:
file.save(os.path.join(app.config['UPLOAD_DIRECTORY'], secure_filename(file.filename)))
return redirect('/')
@app.route('/analyze', methods = ['GET'])
def analyze():
file_list = os.listdir(app.config['UPLOAD_DIRECTORY'])
contents = []
for file_name in file_list:
with open(os.path.join(app.config['UPLOAD_DIRECTORY'], file_name), 'r') as file:
content = file.read()
words = content.split()
word_counts = {}
for word in words:
if word not in word_counts:
word_counts[word] = 1
else:
word_counts[word] += 1
contents.append((file_name, word_counts))
return render_template('analyze.html', contents=contents)
if __name__ == '__main__':
app.run(debug=True)
\ No newline at end of file
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
.app {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.form-section {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
padding: 20px;
margin-bottom: 20px;
}
form {
height: 100px;
display: flex;
flex-direction: column;
align-items: center;
}
input[type="file"] {
padding: 10px;
margin-bottom: 10px;
border-radius: 5px;
border: none;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
input[type="file"] {
width: 100%;
height: 50px;
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
color: #333;
padding: 10px;
font-size: 16px;
font-weight: bold;
}
\ No newline at end of file
{% extends "layout.html" %}
{% block content %}
<h1>Analysis Results</h1>
<ul>
{% for content in contents %}
<li>
<h3>{{ content[0] }}</h3>
<ul>
{% for word, count in content[1].items() %}
<li>{{ word }} : {{count}}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{%endblock%}
\ No newline at end of file
{% extends "layout.html" %}
{% block content %}
<div class = "app">
<div class="form-section">
<form action="/upload" method = "post" enctype="multipart/form-data">
<input type="file" name = "file" id = "file-input">
<input type="submit" value = "Upload">
</form>
</div>
<div class="images-section">
</div>
</div>
{%endblock%}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
crossorigin="anonymous"
/>
<title>File Uploads</title>
<link rel="stylesheet" href="{{ url_for('static', filename = 'style.css') }}">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="collapse navbar-collapse" id="navbar">
<div class="navbar-nav">
<a class="nav-item nav-link" id="home" href="/">Home</a>
<a class="nav-item nav-link" id="logout" href="/analyze">analyze</a>
</div>
</div>
</nav>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class="flashes">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
<div id="content">
{% block content %}
{% endblock %}
</div>
</body>
</html>
\ No newline at end of file
My name is Ziyan.Lu and Fuck you
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment