2024-01-16 16:05:42 +04:00
|
|
|
import os
|
|
|
|
from flask import Flask, render_template
|
|
|
|
|
|
|
|
app = Flask(__name__, template_folder='')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def home():
|
|
|
|
return render_template("index.html")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/ex')
|
|
|
|
def do():
|
|
|
|
current_directory = os.getcwd()
|
|
|
|
directory_elements = current_directory.split(os.path.sep) # Разделяем по разделителю каталогов
|
|
|
|
cur_d = os.path.sep.join(directory_elements[:-1])
|
|
|
|
path_data_file = cur_d + '/var/result/data.txt'
|
|
|
|
path_result_file = cur_d + '/var/result/result.txt'
|
|
|
|
|
|
|
|
min_number = 0
|
|
|
|
try:
|
|
|
|
# Чтение чисел из файла
|
|
|
|
with open(path_data_file, 'r') as file:
|
|
|
|
numbers = [float(line.strip()) for line in file]
|
|
|
|
|
|
|
|
# Поиск минимального числа
|
|
|
|
min_number = min(numbers)
|
|
|
|
|
|
|
|
# Возведение минимального числа в третью степень
|
|
|
|
result = min_number ** 3
|
|
|
|
|
|
|
|
# Запись результата в файл
|
|
|
|
with open(path_result_file, 'w') as result_file:
|
|
|
|
result_file.write(str(result))
|
|
|
|
|
|
|
|
print(f'Наименьшее число из файла {path_data_file} в третьей степени сохранено в {path_result_file}.')
|
|
|
|
except Exception as e:
|
|
|
|
print(f'Произошла ошибка: {e}')
|
|
|
|
|
|
|
|
return render_template("result.html", num=min_number)
|
|
|
|
|
|
|
|
|
|
|
|
app.run(host='0.0.0.0', port=8082)
|