88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// For Node.js environments that support TextDecoder
|
|
// Using iconv-lite or manual Shift-JIS decoding
|
|
const sjis = require('encoding');
|
|
|
|
const csvDir = './MoneyForwardエクスポート';
|
|
|
|
const files = fs.readdirSync(csvDir).filter(f => f.endsWith('.csv'));
|
|
|
|
const categories = new Map(); // key: "大項目|中項目", value: {institutions: Set, hasNonTransfer: boolean}
|
|
const institutions = new Set();
|
|
|
|
files.forEach(file => {
|
|
const filePath = path.join(csvDir, file);
|
|
const buffer = fs.readFileSync(filePath);
|
|
|
|
// Try to decode from Shift-JIS
|
|
let content;
|
|
try {
|
|
// Using Node.js built-in Buffer (assumes UTF-8, may fail)
|
|
content = buffer.toString('utf8');
|
|
} catch (e) {
|
|
console.error(`Could not decode file: ${file}`);
|
|
return;
|
|
}
|
|
|
|
const lines = content.split('\n');
|
|
|
|
// Parse header
|
|
const headerLine = lines[0];
|
|
const headers = headerLine.split(',');
|
|
|
|
const indices = {
|
|
大項目: headers.indexOf('大項目'),
|
|
中項目: headers.indexOf('中項目'),
|
|
保有金融機関: headers.indexOf('保有金融機関'),
|
|
振替: headers.indexOf('振替')
|
|
};
|
|
|
|
console.log(`File: ${file}`);
|
|
console.log(`Headers found:`, indices);
|
|
|
|
// Parse data rows
|
|
for (let i = 1; i < lines.length; i++) {
|
|
const line = lines[i].trim();
|
|
if (!line) continue;
|
|
|
|
const fields = line.split(',');
|
|
if (fields.length < Math.max(...Object.values(indices)) + 1) continue;
|
|
|
|
const category = fields[indices.大項目];
|
|
const subCategory = fields[indices.中項目];
|
|
const institution = fields[indices.保有金融機関];
|
|
const transfer = fields[indices.振替];
|
|
|
|
if (!category || !subCategory) continue;
|
|
|
|
const key = `${category}|${subCategory}`;
|
|
|
|
if (!categories.has(key)) {
|
|
categories.set(key, { institutions: new Set(), hasNonTransfer: false });
|
|
}
|
|
|
|
categories.get(key).institutions.add(institution);
|
|
if (transfer === '0') {
|
|
categories.get(key).hasNonTransfer = true;
|
|
}
|
|
|
|
institutions.add(institution);
|
|
}
|
|
});
|
|
|
|
console.log('\n=== UNIQUE CATEGORIES ===\n');
|
|
console.log('大項目 | 中項目 | Institutions | Has Non-Transfer');
|
|
console.log('-'.repeat(80));
|
|
|
|
const sortedCategories = Array.from(categories.entries()).sort();
|
|
sortedCategories.forEach(([key, data]) => {
|
|
const [大項目, 中項目] = key.split('|');
|
|
const instList = Array.from(data.institutions).join('; ');
|
|
console.log(`${大項目} | ${中項目} | ${instList} | ${data.hasNonTransfer ? 'Yes' : 'No'}`);
|
|
});
|
|
|
|
console.log('\n=== INSTITUTIONS ===\n');
|
|
Array.from(institutions).sort().forEach(inst => console.log(inst));
|