From e88167fe3344d82dcd12b1c671f25a10cc85f524 Mon Sep 17 00:00:00 2001 From: "vladimir.buzalka" Date: Tue, 30 Sep 2025 08:32:57 +0200 Subject: [PATCH] Z230 --- DropBoxWhereIs.py | 64 ++++++++++++++++++++++++++++++++++++++++ PDFmanipulationBetter.py | 17 +++++++++++ 2 files changed, 81 insertions(+) create mode 100644 DropBoxWhereIs.py create mode 100644 PDFmanipulationBetter.py diff --git a/DropBoxWhereIs.py b/DropBoxWhereIs.py new file mode 100644 index 0000000..ff5d495 --- /dev/null +++ b/DropBoxWhereIs.py @@ -0,0 +1,64 @@ +from __future__ import annotations +import os, json, sys +from pathlib import Path + +def get_dropbox_root(prefer: str = "personal") -> Path: + """ + Return the Dropbox root folder as a Path. + prefer: "personal" or "business" if both are configured. + You can override via env var DROPBOX_ROOT. + """ + # 0) explicit override + env_override = os.environ.get("DROPBOX_ROOT") + if env_override: + p = Path(env_override).expanduser() + if p.exists(): + return p + + # 1) official info.json locations + candidates = [] + if sys.platform.startswith("win"): + appdata = os.environ.get("APPDATA") + localappdata = os.environ.get("LOCALAPPDATA") + if appdata: candidates.append(Path(appdata) / "Dropbox" / "info.json") + if localappdata:candidates.append(Path(localappdata) / "Dropbox" / "info.json") + else: + candidates.append(Path.home() / ".dropbox" / "info.json") + + for jpath in candidates: + try: + if jpath.is_file(): + data = json.loads(jpath.read_text(encoding="utf-8")) + # data might have "personal" and/or "business" + choices = [] + if "personal" in data and "path" in data["personal"]: + choices.append(("personal", Path(data["personal"]["path"]))) + if "business" in data and "path" in data["business"]: + choices.append(("business", Path(data["business"]["path"]))) + if choices: + # pick preferred, else first available + for kind, p in choices: + if kind == prefer and p.exists(): + return p + # fallback to any existing + for _, p in choices: + if p.exists(): + return p + except Exception: + pass # ignore and try fallbacks + + # 2) common defaults as a last resort + guesses = [ + Path.home() / "Dropbox", + Path.home() / "Dropbox (Personal)", + Path.home() / "Dropbox (Business)", + ] + for p in guesses: + if p.exists(): + return p + + raise FileNotFoundError( + "Could not locate Dropbox root. Set DROPBOX_ROOT env var to override." + ) + +print (get_dropbox_root("personal")) \ No newline at end of file diff --git a/PDFmanipulationBetter.py b/PDFmanipulationBetter.py new file mode 100644 index 0000000..3ded13c --- /dev/null +++ b/PDFmanipulationBetter.py @@ -0,0 +1,17 @@ +from pathlib import Path +import os +from pikepdf import Pdf, Name + +def set_single_page_view(filepdfin: str | os.PathLike): + filepdfin = Path(filepdfin) + with Pdf.open(filepdfin, allow_overwriting_input=True) as pdf: + pdf.Root.PageLayout = Name('/SinglePage') # one page at a time, no continuous scroll + pdf.Root.PageMode = Name('/UseNone') # no thumbnails/bookmarks on open + # Optional: keep file ID stable and re-linearize for "Fast Web View" + pdf.save(filepdfin, static_id=True, linearize=True) + +cesta = r"z:\dropbox\ordinace\Dokumentace_ke_zpracování" +for name in os.listdir(cesta): + p = os.path.join(cesta, name) + if os.path.isfile(p) and name.upper().endswith(".PDF"): + set_single_page_view(p)