diff --git a/index.html b/index.html
index a1a794b..904a956 100644
--- a/index.html
+++ b/index.html
@@ -2,117 +2,270 @@
+
- YAML Editor
-
+ Invoice Email Sender
+
-
-
-
-
-
+
+
Configuration
+
CSV Management
+
Email Operations
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Status: Ready
diff --git a/main.py b/main.py
index 018ae5d..bdfd8aa 100644
--- a/main.py
+++ b/main.py
@@ -15,7 +15,7 @@ import logging
app = Flask(__name__, static_folder='.', static_url_path='')
logging.basicConfig(level=logging.INFO)
-DATA_FILE = 'data.yaml'
+DATA_FILE = 'config.yaml' # Ensure this is the correct path to your YAML file
def read_yaml():
@@ -23,17 +23,20 @@ def read_yaml():
Reads and returns content from the YAML file.
Returns:
- dict: A dictionary with the key 'text' containing file content.
+ dict: A dictionary with the key 'email' and 'email_template' containing their respective contents.
None: If an error occurs, along with an error message.
"""
file_path = Path(DATA_FILE)
try:
if not file_path.is_file():
logging.info("YAML file not found. Returning empty data.")
- return {'text': ''}, None
+ return {'email': {}, 'email_template': ''}, None
with file_path.open() as file:
data = yaml.safe_load(file) or {}
- return {'text': data.get('text', '')}, None
+ return {
+ 'email': data.get('email', {}),
+ 'email_template': data.get('email_template', '')
+ }, None
except yaml.YAMLError as e:
logging.error(f"YAML Error: {e}", exc_info=True)
return None, f"YAML parsing error: {e}"
@@ -45,12 +48,13 @@ def read_yaml():
return None, f"Unexpected error: {e}"
-def write_yaml(content):
+def write_yaml(email_data, email_template_data):
"""
Writes content to the YAML file.
Args:
- content (str): The text content to be saved in the file.
+ email_data (dict): The data for the 'email' section.
+ email_template_data (str): The data for the 'email_template' section.
Returns:
bool: True if the operation was successful, False otherwise.
@@ -59,7 +63,10 @@ def write_yaml(content):
file_path = Path(DATA_FILE)
try:
with file_path.open('w') as file:
- yaml.dump({'text': content}, file)
+ yaml.dump({
+ 'email': email_data,
+ 'email_template': email_template_data
+ }, file)
return True, None
except Exception as e:
logging.error(f"Error writing YAML file: {e}", exc_info=True)
@@ -75,19 +82,20 @@ def handle_data():
Returns:
JSON response for GET requests.
- Text message for POST requests.
+ JSON response for POST requests indicating success or failure.
"""
if request.method == 'GET':
data, error = read_yaml()
if error:
- return error, 500
+ return jsonify({'success': False, 'message': error}), 500
return jsonify(data), 200
elif request.method == 'POST':
- content = request.json.get('text', '')
- success, error = write_yaml(content)
+ email_data = request.json.get('email', {})
+ email_template_data = request.json.get('email_template', '')
+ success, error = write_yaml(email_data, email_template_data)
if error:
- return error, 500
- return "File saved successfully", 200
+ return jsonify({'success': False, 'message': error}), 500
+ return jsonify({'success': True, 'message': "File saved successfully"}), 200
@app.route('/')