Spaces:
Running
Running
| 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 | |