fix(financial): update eKRS API key paths and date format parsing
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
eKRS API changed: financial reports are now under dzial3.wzmiankiOZlozonychDokumentach.wzmiankaOZlozeniuRocznegoSprawozdaniaFinansowego (not dzial3.sprawozdaniaFinansowe). Date format changed from YYYY-MM-DD to DD.MM.YYYY and period from separate fields to combined "OD DD.MM.YYYY DO DD.MM.YYYY" string. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0a66905b1c
commit
e75f33126b
@ -195,8 +195,14 @@ def process_company(db, company, dry_run=False):
|
||||
pass
|
||||
|
||||
# Check for sprawozdania in dzial3
|
||||
sprawozdania = dzial3.get('sprawozdaniaFinansowe', {})
|
||||
wzmianki = sprawozdania.get('informacjeOSprWorzdawozdaniach', [])
|
||||
# eKRS API stores financial reports under wzmiankiOZlozonychDokumentach
|
||||
wzmianki_docs = dzial3.get('wzmiankiOZlozonychDokumentach', {})
|
||||
wzmianki = wzmianki_docs.get('wzmiankaOZlozeniuRocznegoSprawozdaniaFinansowego', [])
|
||||
|
||||
# Fallback to old key structure
|
||||
if not wzmianki:
|
||||
sprawozdania = dzial3.get('sprawozdaniaFinansowe', {})
|
||||
wzmianki = sprawozdania.get('informacjeOSprWorzdawozdaniach', [])
|
||||
|
||||
if not wzmianki:
|
||||
logger.info(f' No financial reports found in KRS data')
|
||||
@ -205,16 +211,36 @@ def process_company(db, company, dry_run=False):
|
||||
updated = False
|
||||
for wzmianka in wzmianki:
|
||||
if isinstance(wzmianka, dict):
|
||||
from datetime import datetime as dt
|
||||
import re as re_mod
|
||||
|
||||
# New format: "zaOkresOdDo": "OD 01.01.2024 DO 31.12.2024"
|
||||
# Old format: "okresOd": "2024-01-01", "okresDo": "2024-12-31"
|
||||
okres_od = wzmianka.get('okresOd', '')
|
||||
okres_do = wzmianka.get('okresDo', '')
|
||||
data_zlozenia = wzmianka.get('dataZlozenia', '')
|
||||
|
||||
# Parse combined period field
|
||||
za_okres = wzmianka.get('zaOkresOdDo', '')
|
||||
if za_okres and not okres_od:
|
||||
match = re_mod.search(r'OD\s+(\d{2}\.\d{2}\.\d{4})\s+DO\s+(\d{2}\.\d{2}\.\d{4})', za_okres)
|
||||
if match:
|
||||
okres_od = match.group(1)
|
||||
okres_do = match.group(2)
|
||||
|
||||
if okres_od and okres_do:
|
||||
from datetime import datetime as dt
|
||||
try:
|
||||
p_start = dt.strptime(okres_od, '%Y-%m-%d').date()
|
||||
p_end = dt.strptime(okres_do, '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
# Try multiple date formats
|
||||
for fmt in ['%Y-%m-%d', '%d.%m.%Y']:
|
||||
try:
|
||||
p_start = dt.strptime(okres_od, fmt).date()
|
||||
p_end = dt.strptime(okres_do, fmt).date()
|
||||
break
|
||||
except ValueError:
|
||||
continue
|
||||
else:
|
||||
continue
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
# Check if we already have data with financial figures
|
||||
@ -239,10 +265,12 @@ def process_company(db, company, dry_run=False):
|
||||
db.add(existing)
|
||||
|
||||
if data_zlozenia:
|
||||
try:
|
||||
existing.filed_at = dt.strptime(data_zlozenia, '%Y-%m-%d').date()
|
||||
except ValueError:
|
||||
pass
|
||||
for fmt in ['%Y-%m-%d', '%d.%m.%Y']:
|
||||
try:
|
||||
existing.filed_at = dt.strptime(data_zlozenia, fmt).date()
|
||||
break
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
updated = True
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user