-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_memory_codes.js
More file actions
88 lines (73 loc) · 3.05 KB
/
Copy pathupdate_memory_codes.js
File metadata and controls
88 lines (73 loc) · 3.05 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
const fs = require('fs');
const path = require('path');
// Function to extract fragment info from a txt file
function extractFragmentInfo(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n');
// Look for the fragment line (usually line 2)
for (const line of lines) {
const match = line.match(/fragment (\d) of \d, memory code: (\w+)/);
if (match) {
const fragmentNumber = match[1];
const memoryCode = match[2];
return `${memoryCode}${fragmentNumber}`;
}
}
return null;
} catch (error) {
console.error(`Error reading ${filePath}:`, error.message);
return null;
}
}
// Function to update the encrypted memories CSV
function updateEncryptedMemoriesCSV() {
const rememberDir = path.join(__dirname, 'stages', '6_REMEMBER');
const csvFile = path.join(__dirname, 'encrypted_memories.csv');
try {
// Read the current CSV
const csvContent = fs.readFileSync(csvFile, 'utf8');
const lines = csvContent.split('\n');
// Process each line (skip header)
const updatedLines = [lines[0]]; // Keep header with memory_code column
for (let i = 1; i < lines.length; i++) {
const line = lines[i].trim();
if (!line) continue; // Skip empty lines
// Parse CSV line - extract number and encryption
const match = line.match(/^(\d+),"([^"]+)"(?:,(.*))?$/);
if (!match) {
console.warn(`Could not parse line: ${line}`);
updatedLines.push(line);
continue;
}
const number = match[1];
const encryption = match[2];
// Get fragment info from corresponding txt file
const txtFile = path.join(rememberDir, `${number}.txt`);
const memoryCode = extractFragmentInfo(txtFile);
if (memoryCode) {
updatedLines.push(`${number},"${encryption}",${memoryCode}`);
console.log(`✅ Updated ${number} with memory code: ${memoryCode}`);
} else {
console.warn(`❌ Could not extract memory code for ${number}`);
updatedLines.push(`${number},"${encryption}",UNKNOWN`);
}
}
// Write updated CSV
const newContent = updatedLines.join('\n');
fs.writeFileSync(csvFile, newContent);
console.log(`\n🎉 Successfully updated encrypted_memories.csv with ${updatedLines.length - 1} entries`);
console.log(`📁 Updated file: ${csvFile}`);
} catch (error) {
console.error('❌ Error updating CSV:', error.message);
}
}
// Run the script
if (require.main === module) {
console.log('🔧 Updating encrypted memories CSV with memory codes...');
updateEncryptedMemoriesCSV();
}
module.exports = {
extractFragmentInfo,
updateEncryptedMemoriesCSV
};