Create foia_requests.py
Browse files- foia_requests.py +52 -0
foia_requests.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, List
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import uuid
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
FOIA_STORE = "data/foia_requests.json"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _load_requests() -> List[Dict]:
|
| 11 |
+
if not os.path.exists(FOIA_STORE):
|
| 12 |
+
return []
|
| 13 |
+
try:
|
| 14 |
+
with open(FOIA_STORE, "r", encoding="utf-8") as f:
|
| 15 |
+
return json.load(f)
|
| 16 |
+
except Exception:
|
| 17 |
+
return []
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def _save_requests(requests: List[Dict]) -> None:
|
| 21 |
+
os.makedirs(os.path.dirname(FOIA_STORE), exist_ok=True)
|
| 22 |
+
with open(FOIA_STORE, "w", encoding="utf-8") as f:
|
| 23 |
+
json.dump(requests, f, indent=2)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def add_foia_request(
|
| 27 |
+
agency: str,
|
| 28 |
+
subject: str,
|
| 29 |
+
description: str,
|
| 30 |
+
requester_type: str = "Journalist"
|
| 31 |
+
) -> Dict:
|
| 32 |
+
"""
|
| 33 |
+
Store a FOIA request record (tracking only).
|
| 34 |
+
No submission to agencies is performed.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
record = {
|
| 38 |
+
"id": str(uuid.uuid4()),
|
| 39 |
+
"timestamp": datetime.utcnow().isoformat() + "Z",
|
| 40 |
+
"agency": agency,
|
| 41 |
+
"subject": subject,
|
| 42 |
+
"description": description,
|
| 43 |
+
"requester_type": requester_type,
|
| 44 |
+
"status": "Draft",
|
| 45 |
+
"notes": "Generated by FOIA Declassified Document Search (tracking only)"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
requests = _load_requests()
|
| 49 |
+
requests.append(record)
|
| 50 |
+
_save_requests(requests)
|
| 51 |
+
|
| 52 |
+
return record
|