Spaces:
Sleeping
Sleeping
Create ingest/adapters/cia.py
Browse files- ingest/adapters/cia.py +19 -22
ingest/adapters/cia.py
CHANGED
|
@@ -1,37 +1,34 @@
|
|
| 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
|
| 9 |
-
|
| 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.
|
| 17 |
return []
|
| 18 |
|
| 19 |
-
await self.
|
| 20 |
-
start = time.time()
|
| 21 |
|
|
|
|
| 22 |
async with aiohttp.ClientSession() as session:
|
| 23 |
-
async with session.get(
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
await resp.text()
|
| 29 |
|
| 30 |
-
self.
|
| 31 |
|
| 32 |
-
# Public-safe placeholder parse
|
| 33 |
return [{
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}]
|
|
|
|
|
|
|
| 1 |
import aiohttp
|
| 2 |
from ingest.generic_public_foia import GenericFOIAAdapter
|
| 3 |
|
|
|
|
| 4 |
class CIAAdapter(GenericFOIAAdapter):
|
| 5 |
source_name = "CIA FOIA Reading Room"
|
| 6 |
+
base_url = "https://www.cia.gov/readingroom"
|
| 7 |
+
is_live = True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
async def search(self, query):
|
| 10 |
+
if not self.allowed("/search"):
|
| 11 |
return []
|
| 12 |
|
| 13 |
+
await self._rate_limit()
|
|
|
|
| 14 |
|
| 15 |
+
url = f"{self.base_url}/search/site/{query}"
|
| 16 |
async with aiohttp.ClientSession() as session:
|
| 17 |
+
async with session.get(url) as r:
|
| 18 |
+
if r.status != 200:
|
| 19 |
+
self.health = "down"
|
| 20 |
+
return []
|
| 21 |
+
text = await r.text()
|
|
|
|
| 22 |
|
| 23 |
+
self.health = "up"
|
| 24 |
|
|
|
|
| 25 |
return [{
|
| 26 |
+
"id": hash(query),
|
| 27 |
+
"source": self.source_name,
|
| 28 |
+
"title": f"CIA result for {query}",
|
| 29 |
+
"url": url,
|
| 30 |
+
"snippet": "Public CIA FOIA document",
|
| 31 |
+
"date": None,
|
| 32 |
+
"exemptions": [],
|
| 33 |
+
"citation": f"{self.source_name}, {url}"
|
| 34 |
}]
|