Spaces:
Running
Running
File size: 4,858 Bytes
96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 bb97ea5 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb c0caea8 96dcaeb 135072e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
from flask import Flask, render_template, request, jsonify, send_file, redirect, url_for
import validators
import os
import tempfile
import uuid
from modules.technical_seo import TechnicalSEOModule
from modules.content_audit import ContentAuditModule
from report_generator import ReportGenerator
from simple_pdf_generator import SimplePDFGenerator
app = Flask(__name__, static_folder='static')
app.secret_key = 'seo_report_generator_2024'
# Initialize modules
technical_module = TechnicalSEOModule()
content_module = ContentAuditModule()
report_gen = ReportGenerator()
pdf_gen = SimplePDFGenerator()
# Store for generated reports (in production, use database)
reports_store = {}
@app.route('/')
def index():
return render_template('index.html')
@app.route('/generate', methods=['POST'])
def generate_report():
try:
data = request.json
url = data.get('url', '').strip()
competitors = data.get('competitors', [])
if not url:
return jsonify({'error': 'Website URL is required'}), 400
if not validators.url(url):
return jsonify({'error': 'Please enter a valid URL'}), 400
# Generate unique report ID
report_id = str(uuid.uuid4())
# Validate competitor URLs
competitor_list = []
for comp in competitors:
comp = comp.strip()
if comp and validators.url(comp):
competitor_list.append(comp)
# Technical SEO Analysis
technical_data = technical_module.analyze(url)
# Content Audit
content_data = content_module.analyze(url)
# Competitor Analysis
competitor_data = []
for comp_url in competitor_list:
comp_technical = technical_module.analyze(comp_url)
comp_content = content_module.analyze(comp_url, quick_scan=True)
competitor_data.append({
'url': comp_url,
'technical': comp_technical,
'content': comp_content
})
# Generate HTML report
report_html = report_gen.generate_html_report(
url=url,
technical_data=technical_data,
content_data=content_data,
competitor_data=competitor_data,
include_charts=True
)
# Store report
reports_store[report_id] = {
'url': url,
'html': report_html,
'technical_data': technical_data,
'content_data': content_data,
'competitor_data': competitor_data
}
return jsonify({
'success': True,
'report_id': report_id,
'redirect_url': f'/report/{report_id}'
})
except Exception as e:
return jsonify({'error': f'Error generating report: {str(e)}'}), 500
@app.route('/report/<report_id>')
def view_report(report_id):
if report_id not in reports_store:
return redirect(url_for('index'))
report_data = reports_store[report_id]
return render_template('report.html',
report_html=report_data['html'],
report_id=report_id,
url=report_data['url'])
@app.route('/download/<report_id>')
def download_html(report_id):
if report_id not in reports_store:
return jsonify({'error': 'Report not found'}), 404
report_data = reports_store[report_id]
# Create temporary file
with tempfile.NamedTemporaryFile(mode='w', suffix='.html', delete=False) as f:
f.write(report_data['html'])
temp_path = f.name
filename = f"seo_report_{report_data['url'].replace('https://', '').replace('http://', '').replace('/', '_')}.html"
return send_file(temp_path, as_attachment=True, download_name=filename, mimetype='text/html')
@app.route('/download-pdf/<report_id>')
def download_pdf(report_id):
if report_id not in reports_store:
return jsonify({'error': 'Report not found'}), 404
try:
report_data = reports_store[report_id]
# Generate PDF
pdf_data = pdf_gen.generate_pdf(report_data['html'])
# Create temporary file
with tempfile.NamedTemporaryFile(suffix='.pdf', delete=False) as f:
f.write(pdf_data)
temp_path = f.name
filename = f"seo_report_{report_data['url'].replace('https://', '').replace('http://', '').replace('/', '_')}.pdf"
return send_file(temp_path, as_attachment=True, download_name=filename, mimetype='application/pdf')
except Exception as e:
return jsonify({'error': f'PDF generation failed: {str(e)}'}), 500
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port=7860) |