DmitrMakeev's picture
Update app.py
ed7eab5
raw
history blame
956 Bytes
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
txt_file = request.files['txt_file']
# Считываем строки из загруженного файла TXT
lines = txt_file.read().decode().split("
")
# Создаем словарь в формате JSON
json_data = {str(index+1): line.strip() for index, line in enumerate(lines)}
# Записываем данные в файл JSON
with open('output.json', 'w') as json_file:
json_file.write(jsonify(json_data).get_data(as_text=True))
return 'Файл успешно обработан и создан файл JSON'
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))