Skip to main content
Glama
josuekongolo

CompanyIQ MCP Server

by josuekongolo
test-openai-parser.jsβ€’5.08 kB
import dotenv from 'dotenv'; dotenv.config(); import { OpenAIVisionParser } from './build/scraper/openai_vision_parser.js'; import { existsSync, readdirSync } from 'fs'; import { resolve } from 'path'; async function testOpenAIParser() { console.log('πŸ§ͺ Testing OpenAI Vision Parser with 2021 PNG Images'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); const apiKey = process.env.OPENAI_API_KEY; if (!apiKey) { console.error('❌ OPENAI_API_KEY not found!'); process.exit(1); } const parser = new OpenAIVisionParser(apiKey); // Path to the 2021 PNG images const pngPath = '/Users/josuekongolo/Downloads/mcp/companyiq-mcp/data/pdfs/png_images/999059198/aarsregnskap_999059198-2021'; if (!existsSync(pngPath)) { console.error(`❌ PNG folder not found: ${pngPath}`); console.error(' Please ensure the PNG images exist at this location'); process.exit(1); } // List PNG files const pngFiles = readdirSync(pngPath) .filter(f => f.endsWith('.png')) .sort((a, b) => { const pageA = parseInt(a.match(/page_(\d+)/)?.[1] || '0'); const pageB = parseInt(b.match(/page_(\d+)/)?.[1] || '0'); return pageA - pageB; }); console.log(`πŸ“ Found ${pngFiles.length} PNG files in:`); console.log(` ${pngPath}\n`); if (pngFiles.length === 0) { console.error('❌ No PNG files found!'); process.exit(1); } console.log('πŸ’‘ Norwegian Γ₯rsregnskap show FULL values in NOK'); console.log(' Example: "20 623" = 20,623 NOK (not 20.6M)'); console.log('\nπŸ”„ Starting extraction from PNG images...\n'); try { const startTime = Date.now(); // Since the PNG files already exist, we'll call parseFinancialPDF // which should find and use the existing PNGs // Create the expected PDF path (even if it doesn't exist, the PNGs do) const pdfPath = '/Users/josuekongolo/Downloads/mcp/companyiq-mcp/data/pdfs/999059198/aarsregnskap_999059198-2021.pdf'; console.log('πŸ“Έ Using existing PNG images for analysis...'); console.log('πŸ“„ Expected PDF path (for reference):', pdfPath); // The parser will look for PNGs in the expected location // Since they already exist, it should use them const result = await parser.parseFinancialPDF(pdfPath); const duration = Math.round((Date.now() - startTime) / 1000); console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'); console.log('πŸ“Š EXTRACTION RESULTS FOR 2021'); console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'); console.log(`⏱️ Time: ${duration} seconds\n`); const formatValue = (name, value) => { if (value === null) { console.log(`${name}: Not found`); return; } // Format based on size if (Math.abs(value) < 1000) { console.log(`${name}: ${value.toLocaleString('no-NO')} NOK`); } else if (Math.abs(value) < 1000000) { const thousands = value / 1000; console.log(`${name}: ${value.toLocaleString('no-NO')} NOK (${thousands.toFixed(1)}K)`); } else { const millions = value / 1000000; console.log(`${name}: ${value.toLocaleString('no-NO')} NOK (${millions.toFixed(1)}M)`); } }; formatValue('πŸ’° Revenue', result.revenue); formatValue('πŸ“ˆ Profit', result.profit); formatValue('🏒 Assets', result.assets); formatValue('πŸ’Ž Equity', result.equity); console.log('\nπŸ” Value Analysis:'); // Check if values look reasonable (not multiplied by 1000) const allValuesReasonable = (!result.revenue || result.revenue < 10000000000) && // Less than 10 billion (!result.profit || Math.abs(result.profit) < 1000000000) && // Less than 1 billion (!result.assets || result.assets < 10000000000) && (!result.equity || result.equity < 10000000000); if (allValuesReasonable) { console.log('βœ… Values appear correct (no TNOK multiplication detected)'); } else { console.log('⚠️ Some values seem too large (possible TNOK issue)'); } // Save the extracted data console.log('\nπŸ’Ύ Extracted data for year 2021:'); console.log(JSON.stringify({ year: 2021, revenue: result.revenue, profit: result.profit, assets: result.assets, equity: result.equity, source: 'openai_vision_extraction' }, null, 2)); console.log('\nβœ… Test completed successfully!'); // Show some sample PNG files that were analyzed console.log('\nπŸ“„ Sample PNG files analyzed:'); pngFiles.slice(0, 3).forEach(file => { console.log(` - ${file}`); }); if (pngFiles.length > 3) { console.log(` ... and ${pngFiles.length - 3} more`); } } catch (error) { console.error('❌ Extraction failed:', error.message); console.error('\nError details:', error); } } testOpenAIParser();

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/josuekongolo/companyiq-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server