28 lines
698 B
Python
28 lines
698 B
Python
from flask import Flask
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route('/')
|
|
def generate_data():
|
|
# из первых строк всех файлов каталога /var/data
|
|
data_dir = '/var/data'
|
|
# формирует файл /var/result/data.txt
|
|
result_file = '/var/result/data.txt'
|
|
|
|
lines = []
|
|
|
|
for filename in os.listdir(data_dir):
|
|
with open(os.path.join(data_dir, filename), 'r') as file:
|
|
lines.append(file.readline())
|
|
|
|
with open(result_file, 'w') as result:
|
|
result.write('\n'.join(lines))
|
|
|
|
return 'Файл успешно сформирован!\n' + str(lines)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000)
|