GodsDevProject commited on
Commit
26921eb
·
verified ·
1 Parent(s): 6ee6967

Create ingest/adapters/cia.py

Browse files
Files changed (1) hide show
  1. 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/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
  }]
 
 
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
  }]