aboutsummaryrefslogtreecommitdiffstats
path: root/file_util.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2026-02-24 20:06:34 -0800
committerPinapelz <yukais@pinapelz.com>2026-02-24 20:57:03 -0800
commitac1ae3d0388c8dc74ccfa2f29644b26e2fc11f81 (patch)
treef9700fbcdcc2f8b7c0251cd46982865dbc788f9e /file_util.py
parentd72f58671c1bb84bea00c660a3044c9033d07da0 (diff)
move file operations to new module
Diffstat (limited to 'file_util.py')
-rw-r--r--file_util.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/file_util.py b/file_util.py
new file mode 100644
index 0000000..154a586
--- /dev/null
+++ b/file_util.py
@@ -0,0 +1,46 @@
+import os
+import json
+import logging
+
+logger = logging.getLogger(__name__)
+
+def _load_urls_from_file(path: str):
+ urls = []
+ if not path:
+ logger.debug("No path provided to load_urls_from_file")
+ return urls
+ try:
+ with open(path, "r", encoding="utf-8") as f:
+ for raw in f:
+ line = raw.strip()
+ if not line:
+ continue
+ if line.startswith("#"):
+ continue
+ if " #" in line:
+ line = line.split(" #", 1)[0].strip()
+ urls.append(line)
+ logger.info("Loaded %d URLs from %s", len(urls), path)
+ except FileNotFoundError:
+ logger.warning("URL file not found: %s", path)
+ except Exception:
+ logger.exception("Failed to read URL file: %s", path)
+ return urls
+
+def _create_or_get_cache(cache_file_path: str):
+ try:
+ if os.path.exists(cache_file_path):
+ with open(cache_file_path, "r", encoding="utf-8") as f:
+ return json.load(f)
+ else:
+ return {}
+ except Exception:
+ logger.exception("Failed to load cache file, starting with empty cache")
+ return {}
+
+def _save_cache(cache_data: dict, cache_file_path: str):
+ try:
+ with open(cache_file_path, "w", encoding="utf-8") as f:
+ json.dump(cache_data, f, ensure_ascii=False, indent=2)
+ except Exception:
+ logger.exception("Failed to save cache to %s", cache_file_path)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage