AW Dev Rethought

βœ‚οΈ Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away - Antoine de Saint-ExupΓ©ry

🧩 Python Automation Recipes – πŸ“Š Automation Dashboard Reporter


Description:

πŸ“Œ Introduction

Automation scripts often generate logs, but raw log files aren’t always easy to read. A simple HTML dashboard makes it much easier to review execution history, identify failures, and share results with your team.

This automation recipe shows how to generate an HTML execution dashboard from task results using Python. The generated report can be opened in any web browser and serves as a lightweight monitoring dashboard.


πŸ”Ž Explanation

  • The script stores automation task results in a Python list.
  • It dynamically generates an HTML report containing:
    • task name
    • execution status
    • execution duration
    • execution timestamp
  • Success and failure rows are color-coded for quick identification.
  • The final report is saved as an HTML file that can be viewed locally or shared.

This pattern is useful for:

  • scheduled automation jobs
  • CI/CD reports
  • batch processing
  • daily execution summaries

βœ… Key Takeaways

  • πŸ“Š Generate visual execution reports automatically.
  • 🌐 View automation history directly in a browser.
  • 🧩 Easy to extend with charts, filters, or execution statistics.

Code Snippet:

from pathlib import Path
from datetime import datetime

# --- Step 1: Sample execution results ---
task_results = [
    {
        "task": "Backup Folder",
        "status": "SUCCESS",
        "duration": "2.3 sec",
    },
    {
        "task": "Generate Report",
        "status": "SUCCESS",
        "duration": "1.7 sec",
    },
    {
        "task": "Send Email",
        "status": "FAILED",
        "duration": "0.5 sec",
    },
    {
        "task": "Cleanup Logs",
        "status": "SUCCESS",
        "duration": "0.9 sec",
    },
]

# Output HTML file
REPORT_FILE = Path("automation_dashboard.html")

# Current timestamp
generated_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

# --- Step 2: Build HTML table rows ---
rows = ""

for task in task_results:

    color = "#28a745" if task["status"] == "SUCCESS" else "#dc3545"

    rows += f"""
    
        {task['task']}
        
            {task['status']}
        
        {task['duration']}
    
    """

# --- Step 3: Build HTML document ---
html = f"""




    Automation Dashboard

    





πŸ“Š Automation Dashboard

Generated: {generated_time}

{rows}
Task Status Duration
""" # --- Step 4: Save HTML report --- REPORT_FILE.write_text(html, encoding="utf-8") print(f"Dashboard generated successfully:") print(REPORT_FILE.resolve())

Link copied!

Comments

Add Your Comment

Comment Added!