feat: implement sourced council publication assessment

This commit is contained in:
codex committed 2026-10-08 18:05:32 +03:00
1 parent 44fadd7289
commit 24d07706e1
37 files changed
+72554 -72

No files matched your search

+8 -5
View File
@@ -13,7 +13,9 @@ import re
import pdfplumber
def extract(source: Path) -> dict:
def extract(source: Path, category: str = "К1") -> dict:
if category not in {"К1", "К2"}:
raise ValueError("Unsupported category")
rows = []
with pdfplumber.open(source) as document:
for page in document.pages:
@@ -31,7 +33,7 @@ def extract(source: Path) -> dict:
raise ValueError("Journal numbering is incomplete or duplicated")
journals = []
for row in rows:
if row[2] != "К1":
if row[2] != category:
continue
name = " ".join(row[1].split())
journal = {"name": name, "categorized_on": row[3], "source_row": int(row[0])}
@@ -42,7 +44,7 @@ def extract(source: Path) -> dict:
journal.update(name=rename[1], note=rename[2], aliases=[rename[3]])
journals.append(journal)
if not journals:
raise ValueError("No K1 journals found")
raise ValueError(f"No {category} journals found")
return {"source": source.name, "source_sha256": hashlib.sha256(source.read_bytes()).hexdigest(),
"source_rows": len(rows), "category_counts": dict(Counter(row[2] for row in rows)),
"journals": journals}
@@ -52,7 +54,8 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source", type=Path)
parser.add_argument("--output", type=Path, default=Path("app/data/k1_journals.json"))
parser.add_argument("--category", choices=["К1", "К2"], default="К1")
args = parser.parse_args()
result = extract(args.source)
result = extract(args.source, args.category)
args.output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", newline="\n")
print(f"Saved {len(result['journals'])} K1 journals; verified {result['source_rows']} source rows")
print(f"Saved {len(result['journals'])} {args.category} journals; verified {result['source_rows']} source rows")