fichiers oubliés
This commit is contained in:
1 parent
d048732613
commit
857efcef18
8 files changed
+722
No files matched your search
@@ -0,0 +1,28 @@
|
||||
"""Provenance of shared answer content, independent of Gemini corrections."""
|
||||
from hashlib import sha256
|
||||
from pathlib import Path
|
||||
|
||||
from .json_io import atomic_update_json, read_json
|
||||
|
||||
|
||||
def _path(root):
|
||||
return Path(root) / ".copienator" / "answer_origins.json"
|
||||
|
||||
|
||||
def origins_for(root, copy_id, label, pdf):
|
||||
entry = read_json(_path(root), default={}).get(str(copy_id), {}).get(label, {})
|
||||
if not entry or not Path(pdf).is_file():
|
||||
return []
|
||||
if entry.get("sha256") != sha256(Path(pdf).read_bytes()).hexdigest():
|
||||
return []
|
||||
return entry.get("labels", [])
|
||||
|
||||
|
||||
def save_origins(root, copy_id, label, pdf, origins):
|
||||
entry = {"labels": list(dict.fromkeys(origins)),
|
||||
"sha256": sha256(Path(pdf).read_bytes()).hexdigest()}
|
||||
|
||||
def update(data):
|
||||
data.setdefault(str(copy_id), {})[label] = entry
|
||||
|
||||
atomic_update_json(_path(root), update, default_factory=dict)
|
||||
Reference in new issue
Block a user