move to python script (no shell) master
authorShane Jaroch <chown_tee@proton.me>
Fri, 23 Jan 2026 19:58:17 +0000 (14:58 -0500)
committerShane Jaroch <chown_tee@proton.me>
Fri, 23 Jan 2026 19:58:17 +0000 (14:58 -0500)
regenerate_fixtures.py [new file with mode: 0755]
regenerate_fixtures.sh [deleted file]

diff --git a/regenerate_fixtures.py b/regenerate_fixtures.py
new file mode 100755 (executable)
index 0000000..93e5e62
--- /dev/null
@@ -0,0 +1,131 @@
+#!/usr/bin/env python3
+import glob
+import json
+import os
+import shutil
+import subprocess
+import sys
+from datetime import datetime, timedelta
+
+
+def update_expiration(cache_dir):
+    """Updates the 'expires' field in requests-cache JSON fixtures to 5 years in the future."""
+    print(f"Updating expiration dates in {cache_dir}...")
+
+    # Calculate 5 years in the future from now
+    future_date = datetime.now() + timedelta(days=365 * 5)
+    # Format as ISO 8601 string, e.g., '2030-01-23T19:30:00'
+    # requests-cache typically uses this format
+    future_expires = future_date.isoformat()
+
+    json_files = glob.glob(os.path.join(cache_dir, "requests", "*.json"))
+    count = 0
+
+    for filepath in json_files:
+        try:
+            with open(filepath, "r", encoding="utf-8") as f:
+                data = json.load(f)
+
+            # Check if it has an 'expires' field (requests-cache format)
+            if "expires" in data:
+                data["expires"] = future_expires
+
+                with open(filepath, "w", encoding="utf-8") as f:
+                    json.dump(data, f, indent=4)
+                count += 1
+        except Exception as e:
+            print(f"Error processing {filepath}: {e}")
+
+    print(f"Updated {count} fixture files in {cache_dir}.")
+
+
+def run_generation(user, person_id, cache_dir, output_file):
+    """Runs the getmyancestors command."""
+    print("========================================")
+    print(f"Regenerating Fixtures for {person_id}")
+    print(f"Cache Dir: {cache_dir}")
+    print("========================================")
+
+    # Clean cache dir
+    if os.path.exists(cache_dir):
+        shutil.rmtree(cache_dir)
+    os.makedirs(cache_dir, exist_ok=True)
+
+    # Construct command
+    # Using sys.executable to ensure we use the same python interpreter
+    cmd = [
+        sys.executable,
+        "-m",
+        "coverage",
+        "run",
+        "-p",
+        "-m",
+        "getmyancestors",
+        "--verbose",
+        "-u",
+        user,
+        "-i",
+        person_id,
+        "-a",
+        "3",
+        "-d",
+        "2",
+        "--rate-limit",
+        "1",
+        "--cache",
+        "--no-cache-control",
+        "--creation-date",
+        "2026-01-01T12:00:00",
+        "-o",
+        output_file,
+    ]
+
+    env = os.environ.copy()
+    env["GMA_CACHE_DIR"] = cache_dir
+
+    try:
+        subprocess.run(cmd, env=env, check=True)
+    except subprocess.CalledProcessError as e:
+        print(f"Error running command: {e}")
+        sys.exit(1)
+
+    # Update expiration after generation
+    update_expiration(cache_dir)
+
+
+def main():
+    user = os.environ.get("FAMILYSEARCH_USER")
+    if not user:
+        print("Error: FAMILYSEARCH_USER not set")
+        sys.exit(1)
+
+    testdata_dir = os.path.dirname(os.path.abspath(__file__))
+    tmp_dir = os.path.join(testdata_dir, ".tmp")
+    os.makedirs(tmp_dir, exist_ok=True)
+
+    # Part 1: Ada (29HC-P5H)
+    run_generation(
+        user=user,
+        person_id="29HC-P5H",
+        cache_dir=os.path.join(testdata_dir, "fixtures", "part1"),
+        output_file=os.path.join(tmp_dir, "regenerate_part1.ged"),
+    )
+
+    print("")
+
+    # Part 2: Marie Curie (LC5H-V1Z)
+    run_generation(
+        user=user,
+        person_id="LC5H-V1Z",
+        cache_dir=os.path.join(testdata_dir, "fixtures", "part2"),
+        output_file=os.path.join(tmp_dir, "regenerate_part2.ged"),
+    )
+
+    print("")
+    print("✅ Regeneration Complete!")
+    print(f"Part 1 Cache: {os.path.join(testdata_dir, 'fixtures', 'part1')}")
+    print(f"Part 2 Cache: {os.path.join(testdata_dir, 'fixtures', 'part2')}")
+
+
+if __name__ == "__main__":
+    main()
diff --git a/regenerate_fixtures.sh b/regenerate_fixtures.sh
deleted file mode 100755 (executable)
index 729bb4b..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/bash
-set -e
-
-# Ensure credentials are present
-if [ -z "$FAMILYSEARCH_USER" ]; then
-       echo "Error: FAMILYSEARCH_USER not set"
-       exit 1
-fi
-
-testdata_dir="$(dirname "$0")"
-mkdir -p "$testdata_dir/.tmp"
-
-echo "========================================"
-echo "Regenerating Fixtures for Part 1 (Ada)"
-echo "========================================"
-export GMA_CACHE_DIR="$testdata_dir/fixtures/part1"
-# Clear existing to ensure clean state
-rm -rf "$GMA_CACHE_DIR"
-mkdir -p "$GMA_CACHE_DIR"
-
-python3 -m coverage run -p -m getmyancestors --verbose \
-       -u "$FAMILYSEARCH_USER" \
-       -i "29HC-P5H" \
-       -a 3 -d 2 \
-       --rate-limit 1 --cache --no-cache-control \
-       --creation-date "2026-01-01T12:00:00" \
-       -o "$testdata_dir/.tmp/regenerate_part1.ged"
-
-echo ""
-echo "========================================"
-echo "Regenerating Fixtures for Part 2 (Marie Curie)"
-echo "========================================"
-export GMA_CACHE_DIR="$testdata_dir/fixtures/part2"
-# Clear existing
-rm -rf "$GMA_CACHE_DIR"
-mkdir -p "$GMA_CACHE_DIR"
-
-python3 -m coverage run -p -m getmyancestors --verbose \
-       -u "$FAMILYSEARCH_USER" \
-       -i "LC5H-V1Z" \
-       -a 3 -d 2 \
-       --rate-limit 1 --cache --no-cache-control \
-       --creation-date "2026-01-01T12:00:00" \
-       -o "$testdata_dir/.tmp/regenerate_part2.ged"
-
-echo ""
-echo "✅ Regeneration Complete!"
-echo "Part 1 Cache: $testdata_dir/fixtures/part1"
-echo "Part 2 Cache: $testdata_dir/fixtures/part2"