forked from ChelseaKR/permit-bearings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan_ordinances.py
More file actions
67 lines (57 loc) · 2.63 KB
/
Copy pathscan_ordinances.py
File metadata and controls
67 lines (57 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""Batch-scan local ordinance texts through the conformance scanner.
Drop ordinance text files at corpus/ordinances/<registry-slug>.txt (PDFs:
extract with pdftotext first) and record provenance in
corpus/ordinances/SOURCES.json. Results land at
data/conformance/results/<slug>.json plus an index the demo site reads.
Usage: python3 scripts/scan_ordinances.py <scanned-on-ISO>
"""
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
from permit_pathways.conformance import load_checks, scan # noqa: E402
def main(scanned_on):
checks = load_checks(ROOT / "data/conformance/checks.json")
sources = json.loads((ROOT / "corpus/ordinances/SOURCES.json").read_text())
registry_slugs = {j["slug"] for j in json.loads(
(ROOT / "data/jurisdictions/registry.json").read_text())["jurisdictions"]}
results_dir = ROOT / "data/conformance/results"
results_dir.mkdir(parents=True, exist_ok=True)
index = {}
for path in sorted((ROOT / "corpus/ordinances").glob("*.txt")):
slug = path.stem
if slug not in registry_slugs:
raise SystemExit(f"{slug}: not a registry slug")
if slug not in sources:
raise SystemExit(f"{slug}: missing provenance in SOURCES.json")
findings = scan(path.read_text(), checks)
out = {
"slug": slug,
"source": sources[slug],
"scanned_on": scanned_on,
"disclaimer": ("Presence-based screening for staff/counsel "
"review; not a certification of compliance and "
"silence is not a clean bill of health."),
"findings": [{
"check_id": f.check.check_id,
"title": f.check.title,
"severity": f.check.severity,
"excerpt": f.excerpt,
"state_law": f.check.state_law,
"hcd_precedent": f.check.hcd_precedent,
} for f in findings],
}
(results_dir / f"{slug}.json").write_text(
json.dumps(out, indent=1) + "\n")
by_sev = {}
for f in findings:
by_sev[f.check.severity] = by_sev.get(f.check.severity, 0) + 1
index[slug] = {"scanned_on": scanned_on,
"findings": len(findings), "by_severity": by_sev,
"source_title": sources[slug]["title"]}
print(f"{slug}: {len(findings)} flag(s) {by_sev}")
(results_dir / "index.json").write_text(json.dumps(index, indent=1) + "\n")
print(f"wrote {len(index)} result file(s) + index")
if __name__ == "__main__":
main(sys.argv[1])