90 lines
3 KiB
Python
90 lines
3 KiB
Python
|
|
"""Compare the two source PDFs against everything stored in PocketBase.
|
||
|
|
|
||
|
|
Answers: which stored slot holds which uploaded file, and is anything stored
|
||
|
|
twice?
|
||
|
|
"""
|
||
|
|
import hashlib
|
||
|
|
import json
|
||
|
|
import urllib.request
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
JEI = Path(r"C:\Users\SJ\.minimax-agent\projects\JEI")
|
||
|
|
env = {}
|
||
|
|
for line in (JEI / ".env.local").read_text(encoding="utf-8").splitlines():
|
||
|
|
line = line.strip()
|
||
|
|
if line and not line.startswith("#") and "=" in line:
|
||
|
|
k, v = line.split("=", 1)
|
||
|
|
env[k.strip()] = v.strip().strip('"').strip("'")
|
||
|
|
PB = env.get("NEXT_PUBLIC_PB_URL") or env["PB_URL"]
|
||
|
|
TOK = env["PB_TOKEN"]
|
||
|
|
|
||
|
|
LOCAL = {
|
||
|
|
"UFC - Shareholders Resolution Director Sune Resigned.pdf":
|
||
|
|
r"C:\Users\SJ\.minimax\v2\assets\2026\10\12\13-41-56-012-asset_20261012-134156-012_a0299b3ae338_88b7c484-UFC - Shareholders Resolution Director Sune Resigned.pdf",
|
||
|
|
"UFC - Sune Resignation Letter.pdf":
|
||
|
|
r"C:\Users\SJ\.minimax\v2\assets\2026\10\12\13-41-56-017-asset_20261012-134156-017_9aec1b4380ba_261a3e6b-UFC - Sune Resignation Letter.pdf",
|
||
|
|
}
|
||
|
|
|
||
|
|
STORED = [
|
||
|
|
("resolution.signed_letter", "pbc_266170881", "e0dbxprazb70rqx", "corrected_v2_avwpnq7o93.pdf"),
|
||
|
|
("resignation.letter", "ysterbaard_director_resignations", "8cfie18uhgy0n0o",
|
||
|
|
"resignation_letter_the_ultimate_fuel_company_1jk8t34nf3.pdf"),
|
||
|
|
("resignation.signature", "ysterbaard_director_resignations", "8cfie18uhgy0n0o",
|
||
|
|
"tbde1evt2m6_8mz8kutpki.pdf"),
|
||
|
|
]
|
||
|
|
|
||
|
|
|
||
|
|
def sha(b: bytes) -> str:
|
||
|
|
return hashlib.sha256(b).hexdigest()
|
||
|
|
|
||
|
|
|
||
|
|
local = {}
|
||
|
|
for label, path in LOCAL.items():
|
||
|
|
p = Path(path)
|
||
|
|
if not p.exists():
|
||
|
|
print(f"MISSING LOCAL: {path}")
|
||
|
|
continue
|
||
|
|
b = p.read_bytes()
|
||
|
|
local[label] = (sha(b), len(b))
|
||
|
|
print(f"LOCAL {len(b):>8} B {sha(b)[:16]} {label}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
|
||
|
|
stored = {}
|
||
|
|
for label, col, rid, fname in STORED:
|
||
|
|
url = f"{PB}/api/files/{col}/{rid}/{urllib.parse.quote(fname)}"
|
||
|
|
req = urllib.request.Request(url, headers={"Authorization": TOK})
|
||
|
|
try:
|
||
|
|
with urllib.request.urlopen(req, timeout=120) as r:
|
||
|
|
b = r.read()
|
||
|
|
except urllib.error.HTTPError as e:
|
||
|
|
print(f"STORED FAIL {label}: HTTP {e.code}")
|
||
|
|
continue
|
||
|
|
stored[label] = (sha(b), len(b))
|
||
|
|
print(f"STORED {len(b):>8} B {sha(b)[:16]} {label}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("=== MATCHES ===")
|
||
|
|
for slabel, (sh, ssize) in stored.items():
|
||
|
|
hits = [l for l, (h, _) in local.items() if h == sh]
|
||
|
|
if hits:
|
||
|
|
print(f" {slabel} == {hits[0]}")
|
||
|
|
else:
|
||
|
|
print(f" {slabel} == (no local file matches — different document)")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("=== DUPLICATES AMONG STORED ===")
|
||
|
|
seen = {}
|
||
|
|
for slabel, (sh, ssize) in stored.items():
|
||
|
|
seen.setdefault(sh, []).append(slabel)
|
||
|
|
for sh, labels in seen.items():
|
||
|
|
if len(labels) > 1:
|
||
|
|
print(f" IDENTICAL ({sh[:16]}, {stored[labels[0]][1]} B): {labels}")
|
||
|
|
else:
|
||
|
|
print(f" unique: {labels[0]}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("=== LOCAL FILES NOT STORED ANYWHERE ===")
|
||
|
|
for l, (h, _) in local.items():
|
||
|
|
if h not in [s for s, _ in stored.values()]:
|
||
|
|
print(f" {l} — uploaded copy does not match any stored file")
|