81 lines
2.5 KiB
TypeScript
81 lines
2.5 KiB
TypeScript
import * as fs from 'fs';
|
|
|
|
async function testParser() {
|
|
console.log('📋 Testing AZDHS parser logic...\n');
|
|
|
|
const fileContent = fs.readFileSync('/home/kelly/Documents/azdhs dispos', 'utf-8');
|
|
const lines = fileContent.split('\n').map(l => l.trim()).filter(l => l.length > 0);
|
|
|
|
console.log(`Total non-empty lines: ${lines.length}\n`);
|
|
|
|
const dispensaries: any[] = [];
|
|
let i = 0;
|
|
let recordCount = 0;
|
|
|
|
while (i < lines.length) {
|
|
// Skip if we hit "Get Details" without processing (edge case)
|
|
if (lines[i] === 'Get Details') {
|
|
i++;
|
|
continue;
|
|
}
|
|
|
|
// Check if next line is "Get Details" (edge case: end of data)
|
|
if (i + 1 < lines.length && lines[i + 1] === 'Get Details') {
|
|
i += 2;
|
|
continue;
|
|
}
|
|
|
|
recordCount++;
|
|
|
|
let name = lines[i];
|
|
let companyName = '';
|
|
let statusLine = '';
|
|
let address = '';
|
|
let linesConsumed = 0;
|
|
|
|
// Check if line i+1 contains "Operating" or "Not Operating" (status line)
|
|
const nextLine = lines[i + 1] || '';
|
|
if (nextLine.includes('Operating')) {
|
|
// Pattern 2: 4-line format (company name = dispensary name)
|
|
companyName = name;
|
|
statusLine = lines[i + 1];
|
|
address = lines[i + 2];
|
|
const getDetails = lines[i + 3];
|
|
|
|
if (getDetails !== 'Get Details') {
|
|
console.log(`⚠️ Record ${recordCount} (4-line) malformed at line ${i}: ${name}`);
|
|
console.log(` Expected "Get Details", got: "${getDetails}"`);
|
|
i++;
|
|
continue;
|
|
}
|
|
linesConsumed = 4;
|
|
console.log(`✅ Record ${recordCount} (4-line): ${name.substring(0, 30)}`);
|
|
} else {
|
|
// Pattern 1: 5-line format (separate company name)
|
|
companyName = lines[i + 1];
|
|
statusLine = lines[i + 2];
|
|
address = lines[i + 3];
|
|
const getDetails = lines[i + 4];
|
|
|
|
if (getDetails !== 'Get Details') {
|
|
console.log(`⚠️ Record ${recordCount} (5-line) malformed at line ${i}: ${name}`);
|
|
console.log(` Expected "Get Details", got: "${getDetails}"`);
|
|
console.log(` Lines: "${name}" | "${companyName}" | "${statusLine}" | "${address}" | "${getDetails}"`);
|
|
i++;
|
|
continue;
|
|
}
|
|
linesConsumed = 5;
|
|
console.log(`✅ Record ${recordCount} (5-line): ${name.substring(0, 30)}`);
|
|
}
|
|
|
|
dispensaries.push({ name, companyName });
|
|
i += linesConsumed;
|
|
}
|
|
|
|
console.log(`\n📊 Total records found: ${dispensaries.length}`);
|
|
console.log(`📊 Expected: 182`);
|
|
console.log(`📊 Difference: ${182 - dispensaries.length}`);
|
|
}
|
|
|
|
testParser();
|