import json from datetime import datetime def generate_html_report(json_data, output_file): # Extract input filename from first check input_file_path = json_data['checks'][0]['config']['input_file'] input_filename = input_file_path.split('/')[-1] # Get just the filename # HTML template with Bootstrap for styling html_template = f''' QC Report - {input_filename}

QC Report: {input_filename}

Generated at: {datetime.fromisoformat(json_data["timestamp"]).strftime('%Y-%m-%d %H:%M:%S')}

{''.join([generate_check_html(check) for check in json_data['checks']])}
''' with open(output_file, 'w') as f: f.write(html_template) def generate_check_html(check): status_color = { 'passed': 'success', 'error': 'danger', 'failed': 'warning' }.get(check['result']['status'].lower(), 'secondary') details_html = format_details(check['result'].get('details', {})) error_html = '' if 'error_message' in check['result']: error_html = f'''
Error:

{check['result']['error_message']}

''' return f'''

{error_html}
Configuration
    {format_details(check['config'])}
Results
    {details_html}
''' def format_details(details, level=0): items = [] for key, value in details.items(): if isinstance(value, dict): items.append(f'''
  • {key.title()}:
    {format_details(value, level+1)}
  • ''') elif isinstance(value, list): list_items = ''.join([f'
  • {item}
  • ' for item in value]) items.append(f'''
  • {key.title()}:
  • ''') else: items.append(f'
  • {key.title()}: {value}
  • ') return '\n'.join(items) # Example usage if __name__ == "__main__": with open('input_report.json') as f: data = json.load(f) generate_html_report(data, 'qc_report.html')