Repository navigation
Expand file tree
/
Copy pathpatch.py
More file actions
53 lines (40 loc) · 2.09 KB
/
Copy pathpatch.py
File metadata and controls
53 lines (40 loc) · 2.09 KB
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
import re
file_path = 'c:/Users/12096/ParcelIQ/frontend/src/components/PropertyDashboard.jsx'
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Replace the handler
old_handler_pattern = r' const handleExportReport = useCallback\(\(\) => \{.+? \}, \[analysisResult, address\]\);'
new_handler = ''' const handleExportReport = useCallback(async () => {
if (!analysisResult) return;
// If not on the dashboard mode, we can't capture the DOM
if (viewMode !== 'dashboard') {
alert('Please switch to the Data Dashboard view first to export the visual report with graphs.');
return;
}
const input = document.getElementById('pdf-export-content');
if (!input) return;
try {
await new Promise(r => setTimeout(r, 100));
const canvas = await html2canvas(input, {
scale: 1.5,
useCORS: true,
backgroundColor: '#0f172a',
logging: false
});
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF('p', 'mm', 'a4');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`ParcelIQ_Risk_Report_${address.replace(/[^a-z0-9]/gi, '_').toLowerCase()}.pdf`);
} catch (error) {
console.error("Failed to generate PDF Export", error);
alert("Sorry, we encountered an error exporting the PDF.");
}
}, [analysisResult, address, viewMode]);'''
content = re.sub(old_handler_pattern, new_handler, content, flags=re.DOTALL)
# Add imports if they don't exist
if 'import jsPDF' not in content:
content = content.replace("import { Download } from 'lucide-react';", "import { Download } from 'lucide-react';\\nimport jsPDF from 'jspdf';\\nimport html2canvas from 'html2canvas';")
with open(file_path, 'w', encoding='utf-8') as f:
f.write(content)