diff --git a/10 SeznamPoskytovatelu.py b/10 SeznamPoskytovatelu.py new file mode 100644 index 0000000..cf2b9cc --- /dev/null +++ b/10 SeznamPoskytovatelu.py @@ -0,0 +1,49 @@ +import shutil +from pathlib import Path + +import requests +from bs4 import BeautifulSoup + +VZP_PAGE = "https://www.vzp.cz/poskytovatele/smluvni-vztahy/seznam-smluvnich-poskytovatelu-zdravotnich-sluzeb" +TARGET_DIR = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování\10 Poskytovatelé") +PREVIOUS_DIR = TARGET_DIR / "Previous" + + +def find_download_url() -> str: + response = requests.get(VZP_PAGE, timeout=30) + response.raise_for_status() + soup = BeautifulSoup(response.text, "html.parser") + for tag in soup.find_all("a", href=True): + href = tag["href"] + if "seznam_pzs" in href and href.endswith(".xlsx"): + return href if href.startswith("http") else "https://www.vzp.cz" + href + raise RuntimeError("Odkaz na soubor nebyl na stránce VZP nalezen.") + + +def main(): + print("Hledám aktuální soubor na stránce VZP...") + url = find_download_url() + filename = url.split("/")[-1] + target_file = TARGET_DIR / filename + + if target_file.exists(): + print(f"Soubor je aktuální: {filename}") + return + + TARGET_DIR.mkdir(parents=True, exist_ok=True) + PREVIOUS_DIR.mkdir(parents=True, exist_ok=True) + + for existing in TARGET_DIR.glob("seznam_pzs_*.xlsx"): + dest = PREVIOUS_DIR / existing.name + shutil.move(str(existing), str(dest)) + print(f"Přesunuto do Previous: {existing.name}") + + print(f"Stahuji: {url}") + response = requests.get(url, timeout=60) + response.raise_for_status() + target_file.write_bytes(response.content) + print(f"Uloženo: {target_file}") + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1190bd8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4