forked from Alexey/DAS_2023_1
37 lines
1016 B
Python
37 lines
1016 B
Python
|
from flask import Flask, redirect, render_template
|
||
|
import os
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
|
||
|
|
||
|
@app.route('/')
|
||
|
def home():
|
||
|
return render_template("index.html")
|
||
|
|
||
|
|
||
|
@app.route('/ex')
|
||
|
def do():
|
||
|
data_dir = '/var/data'
|
||
|
path_result_file = '/var/result/data.txt'
|
||
|
|
||
|
try:
|
||
|
# Получаем список файлов в указанном каталоге
|
||
|
files = os.listdir(data_dir)
|
||
|
|
||
|
# Формируем путь к каждому файлу и считаем количество символов в именах
|
||
|
characters_count_list = [len(file) for file in files]
|
||
|
|
||
|
# Пишем результат в файл data.txt
|
||
|
with open(path_result_file, 'w') as result_file:
|
||
|
for count in characters_count_list:
|
||
|
result_file.write(f'{count}\n')
|
||
|
|
||
|
print(f'Файл успешно создан.')
|
||
|
except Exception as e:
|
||
|
print(f'Произошла ошибка: {e}')
|
||
|
|
||
|
return redirect("/")
|
||
|
|
||
|
|
||
|
app.run(host='0.0.0.0', port=8081)
|