"""Audit active companies for missing KRS/CEIDG data.""" import os, sys sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from sqlalchemy import create_engine, text db_url = os.environ.get('DATABASE_URL', 'postgresql://nordabiz_app:nordabiz_pass@localhost:5433/nordabiz') engine = create_engine(db_url) with engine.connect() as conn: r = conn.execute(text( "SELECT id, name, nip, krs, legal_form, address_street, address_city, " "email, phone, website, data_quality, fee_included_in_parent " "FROM companies WHERE status = 'active' ORDER BY name" )) no_nip = [] no_address = [] no_contact = [] no_legal_form = [] basic_quality = [] for row in r: cid, name, nip, krs, legal_form, street, city, email, phone, website, quality, fee_in_parent = row if not nip and not fee_in_parent: no_nip.append((cid, name)) if not street and not city: no_address.append((cid, name)) if not email and not phone: no_contact.append((cid, name)) if not legal_form: no_legal_form.append((cid, name)) if quality == 'basic': basic_quality.append((cid, name, nip)) print(f'=== Firmy BEZ NIP (nie-podspolki): {len(no_nip)} ===') for cid, name in no_nip: print(f' id={cid:4d} {name}') print(f'\n=== Firmy BEZ adresu: {len(no_address)} ===') for cid, name in no_address: print(f' id={cid:4d} {name}') print(f'\n=== Firmy BEZ kontaktu (email+telefon): {len(no_contact)} ===') for cid, name in no_contact: print(f' id={cid:4d} {name}') print(f'\n=== Firmy BEZ formy prawnej: {len(no_legal_form)} ===') for cid, name in no_legal_form: print(f' id={cid:4d} {name}') print(f'\n=== Firmy z data_quality=basic (minimalne dane): {len(basic_quality)} ===') for cid, name, nip in basic_quality: print(f' id={cid:4d} nip={str(nip or "BRAK"):15s} {name}')