Spaces:
Sleeping
Sleeping
Create ingest/generic_public_foia.py
Browse files- ingest/generic_public_foia.py +36 -28
ingest/generic_public_foia.py
CHANGED
|
@@ -1,29 +1,37 @@
|
|
| 1 |
import time
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
class GenericFOIAAdapter:
|
| 7 |
-
""
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
self.
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
+
import aiohttp
|
| 3 |
+
from ingest.generic_public_foia import GenericFOIAAdapter
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class CIAAdapter(GenericFOIAAdapter):
|
| 7 |
+
source_name = "CIA FOIA Reading Room"
|
| 8 |
+
base_url = "https://www.cia.gov/readingroom/search/site"
|
| 9 |
+
is_stub = False
|
| 10 |
+
|
| 11 |
+
def __init__(self, live: bool = False):
|
| 12 |
+
super().__init__(rate_limit=2.0)
|
| 13 |
+
self.live = live
|
| 14 |
+
|
| 15 |
+
async def search(self, query):
|
| 16 |
+
if not self.live:
|
| 17 |
+
return []
|
| 18 |
+
|
| 19 |
+
await self._throttle()
|
| 20 |
+
start = time.time()
|
| 21 |
+
|
| 22 |
+
async with aiohttp.ClientSession() as session:
|
| 23 |
+
async with session.get(
|
| 24 |
+
self.base_url,
|
| 25 |
+
params={"search_api_fulltext": query},
|
| 26 |
+
timeout=20
|
| 27 |
+
) as resp:
|
| 28 |
+
await resp.text()
|
| 29 |
+
|
| 30 |
+
self.last_latency = time.time() - start
|
| 31 |
+
|
| 32 |
+
# Public-safe placeholder parse
|
| 33 |
+
return [{
|
| 34 |
+
"title": f"CIA FOIA document mentioning '{query}'",
|
| 35 |
+
"url": self.base_url,
|
| 36 |
+
"snippet": "Publicly released FOIA document."
|
| 37 |
+
}]
|