dev.altai / src /reporter.py
prince1604
Initial commit for deployment
b458f3d
Raw
History Blame Contribute Delete
4.41 kB
import json
import os
def generate_json_report(data, output_file="report.json"):
"""
Generates a JSON report of the site analysis.
"""
try:
with open(output_file, 'w') as f:
json.dump(data, f, indent=4)
print(f"JSON report generated at {os.path.abspath(output_file)}")
except Exception as e:
print(f"Error generating JSON report: {e}")
def generate_html_report(data, output_file="report.html"):
"""
Generates an HTML report for the domain scan.
"""
summary = data['summary']
details = data['details']
html = f"""
<!DOCTYPE html>
<html>
<head>
<title>SEO Image Alt Text Report</title>
<style>
body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 20px; background-color: #f4f6f9; }}
h1, h2 {{ color: #333; }}
.container {{ max-width: 1200px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
.summary-box {{ display: flex; gap: 20px; margin-bottom: 30px; }}
.card {{ flex: 1; padding: 20px; border-radius: 8px; color: white; text-align: center; }}
.bg-blue {{ background-color: #007bff; }}
.bg-green {{ background-color: #28a745; }}
.bg-red {{ background-color: #dc3545; }}
.card h3 {{ margin: 0; font-size: 3em; }}
.card p {{ margin: 0; opacity: 0.9; }}
table {{ border-collapse: collapse; width: 100%; margin-top: 10px; }}
th, td {{ border: 1px solid #dee2e6; padding: 12px; text-align: left; }}
th {{ background-color: #f8f9fa; color: #495057; }}
tr:nth-child(even) {{ background-color: #f9f9f9; }}
.page-section {{ margin-bottom: 40px; border-top: 2px solid #eee; padding-top: 20px; }}
.page-url {{ font-size: 1.2em; font-weight: bold; color: #0056b3; margin-bottom: 10px; display: block; }}
.no-issues {{ color: #28a745; font-style: italic; }}
.img-link {{ word-break: break-all; color: #555; }}
</style>
</head>
<body>
<div class="container">
<h1>SEO Image Alt Text Report</h1>
<div class="summary-box">
<div class="card bg-blue">
<h3>{summary['total_pages_scanned']}</h3>
<p>Pages Scanned</p>
</div>
<div class="card bg-green">
<h3>{summary['total_images_found']}</h3>
<p>Total Images Found</p>
</div>
<div class="card bg-red">
<h3>{summary['total_images_missing_alt']}</h3>
<p>Images Missing Alt Text</p>
</div>
</div>
"""
if summary.get('crawl_blocked'):
html += f"""
<div style="background-color: #fff3cd; color: #856404; padding: 15px; border: 1px solid #ffeeba; border-radius: 5px; margin-bottom: 20px;">
<strong>⚠️ CRAWL BLOCKED:</strong> The crawler was blocked by the site ({summary.get('blocked_reason')}). Results are likely incomplete.
<p>Try using a residential proxy or a headless browser with stealth plugins to bypass this restriction.</p>
</div>
"""
html += """
<h2>Detailed Breakdown</h2>
"""
if not details:
html += "<p class='no-issues'>No pages found with missing alt text images! Great job.</p>"
for page in details:
html += f"""
<div class="page-section">
<a href="{page['page_url']}" class="page-url" target="_blank">Page: {page['page_url']}</a>
<p><strong>{page['missing_alt_count']}</strong> images missing alt text</p>
<table>
<tr><th>Image Source URL</th></tr>
"""
for img_src in page['images_without_alt']:
html += f"""
<tr>
<td><a href="{img_src}" target="_blank" class="img-link">{img_src}</a></td>
</tr>
"""
html += "</table></div>"
html += """
</div>
</body>
</html>
"""
try:
with open(output_file, 'w') as f:
f.write(html)
print(f"HTML report generated at {os.path.abspath(output_file)}")
except Exception as e:
print(f"Error generating HTML report: {e}")