-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvToPdfTable.js
More file actions
148 lines (134 loc) · 3.72 KB
/
csvToPdfTable.js
File metadata and controls
148 lines (134 loc) · 3.72 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
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
146
147
148
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
function parseCSVLine(line) {
const result = [];
let current = '';
let inQuotes = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"') {
if (inQuotes && line[i + 1] === '"') {
// Escaped quote
current += '"';
i++; // Skip next quote
} else {
// Toggle quote state
inQuotes = !inQuotes;
}
} else if (char === ',' && !inQuotes) {
// Field separator
result.push(current.trim());
current = '';
} else {
current += char;
}
}
// Add the last field
result.push(current.trim());
return result;
}
function csvToHtmlTable(csvPath, htmlPath) {
const csvContent = fs.readFileSync(csvPath, 'utf8');
const lines = csvContent.trim().split('\n');
if (lines.length === 0) return;
const headers = parseCSVLine(lines[0]);
const rows = lines.slice(1).map(line => parseCSVLine(line));
// Create HTML table with CSS styling
let html = `<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Repository Links Export</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
line-height: 1.4;
}
h1 {
color: #333;
border-bottom: 2px solid #333;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
font-size: 12px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
vertical-align: top;
word-wrap: break-word;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
.repo-name {
max-width: 200px;
word-break: break-all;
}
.channel-name {
max-width: 120px;
}
.category-name {
max-width: 100px;
}
.mention-roles {
max-width: 200px;
word-break: break-word;
}
.last-checked {
max-width: 100px;
}
.footer {
margin-top: 20px;
font-size: 11px;
color: #666;
text-align: center;
}
</style>
</head>
<body>
<h1>Repository Links Export</h1>
<p><strong>Generated on:</strong> ${new Date().toLocaleDateString()} ${new Date().toLocaleTimeString()}</p>
<p><strong>Total Repositories:</strong> ${rows.length}</p>
<table>
<thead>
<tr>
${headers.map(h => `<th>${h}</th>`).join('')}
</tr>
</thead>
<tbody>
${rows.map(row => `
<tr>
<td class="repo-name">${row[0] || ''}</td>
<td class="channel-name">${row[1] || ''}</td>
<td class="category-name">${row[2] || ''}</td>
<td class="mention-roles">${row[3] || ''}</td>
<td class="last-checked">${row[4] || ''}</td>
</tr>`).join('')}
</tbody>
</table>
<div class="footer">
This document was automatically generated by the GeekBot repository management system.
</div>
</body>
</html>`;
fs.writeFileSync(htmlPath, html);
}
async function convertToHtml() {
const csvPath = path.join(__dirname, 'repo_links_export.csv');
const htmlPath = path.join(__dirname, 'repo_links_export.html');
// Convert CSV to HTML table
csvToHtmlTable(csvPath, htmlPath);
console.log(`HTML table created at ${htmlPath}`);
}
convertToHtml();