from flask import Flask, render_template, request, jsonify
import yaml

def read_yaml_file(file_path):
    with open(file_path, 'r') as file:
        try:
            yaml_data = yaml.safe_load(file)
            return yaml_data
        except yaml.YAMLError as e:
            print(f"Error reading YAML file: {e}")

# Provide the path to your YAML file
config_file_path = 'configuration.yaml'

# Read the YAML file
config_content = read_yaml_file(config_file_path)

# Print the YAML content
# print(config_content)

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        form_data = request.get_json()
        generate_yaml(form_data)
        return 'YAML file generated successfully!'
    return render_template('form_template.html', config_content=config_content)

def generate_yaml(data):
    with open('data.yaml', 'w') as file:
        yaml.dump(data, file)

if __name__ == '__main__':
    app.run(debug=True)

