-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplit_data.js
More file actions
45 lines (34 loc) · 1.25 KB
/
Copy pathsplit_data.js
File metadata and controls
45 lines (34 loc) · 1.25 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
const fs = require('fs');
const path = require('path');
const dataPath = path.join(__dirname, 'scammers_data.json');
const rawData = fs.readFileSync(dataPath);
const originalData = JSON.parse(rawData);
const scammers = originalData.data;
const ITEMS_PER_FILE = 100;
const outputDir = path.join(__dirname, 'data');
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir);
}
const totalFiles = Math.ceil(scammers.length / ITEMS_PER_FILE);
const fileIndex = [];
for (let i = 0; i < totalFiles; i++) {
const startIndex = i * ITEMS_PER_FILE;
const endIndex = Math.min((i + 1) * ITEMS_PER_FILE, scammers.length);
const fileData = {
data: scammers.slice(startIndex, endIndex)
};
const fileName = `scammers_${startIndex + 1}_${endIndex}.json`;
const filePath = path.join(outputDir, fileName);
fs.writeFileSync(filePath, JSON.stringify(fileData, null, 2));
fileIndex.push({
fileName,
startId: fileData.data[0].id,
endId: fileData.data[fileData.data.length - 1].id,
count: fileData.data.length
});
}
fs.writeFileSync(
path.join(outputDir, 'index.json'),
JSON.stringify({ files: fileIndex }, null, 2)
);
console.log(`Successfully divided the file into ${totalFiles} small file(s).`);