File size: 1,205 Bytes
afd56bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import logging

logger = logging.getLogger(__name__)


class ISAPClient:
    """
    Klient do odpytywania API Internetowego Systemu Akt贸w Prawnych (ISAP).
    Zapewnia autorytatywn膮 wiedz臋 藕r贸d艂ow膮 np. ujednoliconych tekst贸w ustaw.
    """

    BASE_URL = "http://isap.sejm.gov.pl/api/isap/acts"

    def fetch_act(self, publisher: str, year: int, position: int):
        """
        Pobiera metadane oraz URL do pe艂nego tekstu ujednoliconego z ISAP.
        Przyk艂ad: WDU (Dziennik Ustaw), rocznik, pozycja
        """
        doc_id = f"{publisher}{year}{position:04d}"
        url = f"{self.BASE_URL}/{doc_id}"
        logger.info(f"[ISAP] Odpytywanie o akt prawny: {doc_id}")

        try:
            resp = requests.get(url, timeout=10)
            resp.raise_for_status()
            data = resp.json()

            # Formujemy link to wariantu HTML, by Scraper (Firecrawl) m贸g艂 przeparsowa膰 Markdown.
            text_url = f"{self.BASE_URL}/{doc_id}/text.html"

            return {"id": doc_id, "metadata": data, "text_url": text_url}
        except Exception as e:
            logger.error(f"[ISAP] B艂膮d komunikacji z Sejmowym API: {e}")
            return None